public inbox for
 help / color / mirror / Atom feed
From: Mark Wielaard <>
Cc: Mark Wielaard <>
Subject: [PATCH] debugedit: Handle realloc failure correctly.
Date: Thu,  1 Jul 2021 14:52:35 +0200	[thread overview]
Message-ID: <> (raw)

Although we are already in trouble when realloc fails don't make it
worse.  When realloc fails we have to free the original pointer we
wanted to extend to not cause an even bigger memory leak.

	* tools/debugedit.c (read_abbrev): Free original t after realloc

Signed-off-by: Mark Wielaard <>
 tools/debugedit.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/tools/debugedit.c b/tools/debugedit.c
index c6975b2..7fcaa6a 100644
--- a/tools/debugedit.c
+++ b/tools/debugedit.c
@@ -771,10 +771,14 @@ no_memory:
 	  if (t->nattr == size)
+	      struct abbrev_tag *orig_t = t;
 	      size += 10;
 	      t = realloc (t, sizeof (*t) + size * sizeof (struct abbrev_attr));
 	      if (t == NULL)
-		goto no_memory;
+		{
+		  free (orig_t);
+		  goto no_memory;
+		}
 	  form = read_uleb128 (ptr);
 	  if (form == 2

                 reply	other threads:[~2021-07-01 12:52 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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:

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

  git send-email \ \ \ \

* 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).