]> git.ozlabs.org Git - petitboot/blobdiff - discover/paths.c
discover: pxe: Avoid dereferencing null pointer
[petitboot] / discover / paths.c
index 3a69488e3e87e44dcd508a4ac4ba650d4c18571a..c5b577823746f1c7cab1cc02f176baf494782ff5 100644 (file)
@@ -41,15 +41,6 @@ struct load_task {
        void                    *async_data;
 };
 
-static inline bool have_busybox(void)
-{
-#ifdef WITH_BUSYBOX
-       return true;
-#else
-       return false;
-#endif
-}
-
 const char *mount_base(void)
 {
        return DEVICE_MOUNT_BASE;
@@ -71,6 +62,12 @@ char *join_paths(void *alloc_ctx, const char *a, const char *b)
 
 #ifndef PETITBOOT_TEST
 
+#ifdef WITH_BUSYBOX
+static inline bool have_busybox(void) { return true; }
+#else
+static inline bool have_busybox(void) { return false; }
+#endif
+
 static char *local_name(void *ctx)
 {
        char *ret, tmp[] = "/tmp/pb-XXXXXX";
@@ -436,16 +433,18 @@ static void load_wget(struct load_task *task, int flags)
  */
 static void load_local(struct load_task *task)
 {
+       struct load_url_result *result = task->result;
        int rc;
 
        rc = access(task->url->path, F_OK);
        if (rc) {
-               task->result->status = LOAD_ERROR;
+               result->status = LOAD_ERROR;
        } else {
-               task->result->local = talloc_strdup(task->result,
-                                                   task->url->path);
-               task->result->status = LOAD_OK;
+               result->local = talloc_strdup(task->result, task->url->path);
+               result->status = LOAD_OK;
        }
+
+       task->async_cb(task->result, task->async_data);
 }
 
 static void load_url_async_start_pending(struct load_task *task, int flags)
@@ -618,7 +617,7 @@ struct load_url_result *load_url_async(void *ctx, struct pb_url *url,
                return NULL;
        }
 
-       if (!task->async)
+       if (!task->async || result->status == LOAD_OK)
                talloc_free(task);
 
        return result;