]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
debuginfod: Make sure handle_data can be allocated and is always freed.
authorMark Wielaard <mark@klomp.org>
Tue, 16 Jun 2020 22:08:23 +0000 (00:08 +0200)
committerMark Wielaard <mark@klomp.org>
Wed, 24 Jun 2020 14:37:35 +0000 (16:37 +0200)
When allocating handle_data we should check for out of memory failures.
Also when the allocation has succeeded make sure we always clean up by
going to out1 on any future errors. So move the curl_multi_init call
earlier, because that goes to out0 on failure.

Signed-off-by: Mark Wielaard <mark@klomp.org>
debuginfod/ChangeLog
debuginfod/debuginfod-client.c

index d6bbfac8bf54ae1f6923db89b3f8e930844d4ea6..2bbd5db5b440a4bc67f0936a808f37c3de2e1a0d 100644 (file)
@@ -1,3 +1,8 @@
+2020-06-16  Mark Wielaard  <mark@klomp.org>
+
+       * debuginfod-client.c (debuginfod_query_server): Check malloc.
+       Move curl_multi_init call before handle_data malloc call.
+
 2020-06-16  Mark Wielaard  <mark@klomp.org>
 
        * debuginfod-client.c (debuginfod_query_server): Replace sizeof
index 7b53cb31fa77d129983d72a0ec8e9fc9599e745f..c2aa4e10aafce5621edb443bc429693f20a963da 100644 (file)
@@ -665,10 +665,24 @@ debuginfod_query_server (debuginfod_client *c,
         && (i == 0 || server_urls[i - 1] == url_delim_char))
       num_urls++;
 
+  CURLM *curlm = curl_multi_init();
+  if (curlm == NULL)
+    {
+      rc = -ENETUNREACH;
+      goto out0;
+    }
+
   /* Tracks which handle should write to fd. Set to the first
      handle that is ready to write the target file to the cache.  */
   CURL *target_handle = NULL;
   struct handle_data *data = malloc(sizeof(struct handle_data) * num_urls);
+  if (data == NULL)
+    {
+      rc = -ENOMEM;
+      goto out0;
+    }
+
+  /* thereafter, goto out1 on error.  */
 
   /* Initalize handle_data with default values. */
   for (int i = 0; i < num_urls; i++)
@@ -677,14 +691,6 @@ debuginfod_query_server (debuginfod_client *c,
       data[i].fd = -1;
     }
 
-  CURLM *curlm = curl_multi_init();
-  if (curlm == NULL)
-    {
-      rc = -ENETUNREACH;
-      goto out0;
-    }
-  /* thereafter, goto out1 on error.  */
-
   char *strtok_saveptr;
   char *server_url = strtok_r(server_urls, url_delim, &strtok_saveptr);