public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
From: Mark Wielaard <mark@klomp.org>
To: elfutils-devel@sourceware.org
Cc: Mark Wielaard <mark@klomp.org>
Subject: [PATCH 10/10] debuginfod: Make sure handle_data can be allocated and is always freed.
Date: Wed, 17 Jun 2020 00:25:39 +0200	[thread overview]
Message-ID: <20200616222539.29109-10-mark@klomp.org> (raw)
In-Reply-To: <20200616222539.29109-1-mark@klomp.org>

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           |  5 +++++
 debuginfod/debuginfod-client.c | 22 ++++++++++++++--------
 2 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/debuginfod/ChangeLog b/debuginfod/ChangeLog
index d6bbfac8..2bbd5db5 100644
--- a/debuginfod/ChangeLog
+++ b/debuginfod/ChangeLog
@@ -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
diff --git a/debuginfod/debuginfod-client.c b/debuginfod/debuginfod-client.c
index 7b53cb31..c2aa4e10 100644
--- a/debuginfod/debuginfod-client.c
+++ b/debuginfod/debuginfod-client.c
@@ -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);
 
-- 
2.18.4


  parent reply	other threads:[~2020-06-16 22:26 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-16 22:25 [PATCH 01/10] backends: Make the reloc_nametable zero element an one char array Mark Wielaard
2020-06-16 22:25 ` [PATCH 02/10] libdw: Add missing FALLTHROUGH in execute_cfi Mark Wielaard
2020-06-19 12:56   ` Mark Wielaard
2020-06-16 22:25 ` [PATCH 03/10] elflint: Explicitly check and ignore elf_compress error Mark Wielaard
2020-06-19 13:48   ` Mark Wielaard
2020-06-16 22:25 ` [PATCH 04/10] libdwfl: When we find a compressed image, use that, don't search for others Mark Wielaard
2020-06-19 17:03   ` Mark Wielaard
2020-06-16 22:25 ` [PATCH 05/10] libdwfl: Flag an error if CIE return_address_register is invalid Mark Wielaard
2020-06-19 17:58   ` Mark Wielaard
2020-06-16 22:25 ` [PATCH 06/10] ar, ranlib: Call fchown before fchmod, explicitly check and ignore errors Mark Wielaard
2020-06-19 18:52   ` Mark Wielaard
2020-06-16 22:25 ` [PATCH 07/10] debuginfod: Handle not being able to fopen interval_path Mark Wielaard
2020-06-24 15:04   ` Mark Wielaard
2020-06-16 22:25 ` [PATCH 08/10] debuginfod: Make sure suffix can place zero terminator when copying filename Mark Wielaard
2020-06-16 22:25 ` [PATCH 09/10] debuginfod: Fix build_id hexadecimal length check Mark Wielaard
2020-06-16 22:25 ` Mark Wielaard [this message]
2020-06-19 11:43 ` [PATCH 01/10] backends: Make the reloc_nametable zero element an one char array Mark Wielaard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200616222539.29109-10-mark@klomp.org \
    --to=mark@klomp.org \
    --cc=elfutils-devel@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).