[PATCH] debugedit: Handle realloc failure correctly.
Mark Wielaard
mark@klomp.org
Thu Jul 1 12:52:35 GMT 2021
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
More information about the Debugedit
mailing list