* [PATCH] debugedit: Handle realloc failure correctly.
@ 2021-07-01 12:52 Mark Wielaard
0 siblings, 0 replies; only message in thread
From: Mark Wielaard @ 2021-07-01 12:52 UTC (permalink / raw)
To: debugedit; +Cc: Mark Wielaard
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
fails.
Signed-off-by: Mark Wielaard <mark@klomp.org>
---
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
--
2.18.4
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-07-01 12:52 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-01 12:52 [PATCH] debugedit: Handle realloc failure correctly Mark Wielaard
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).