debugedit: Handle realloc failure correctly.
authorMark Wielaard <mark@klomp.org>
Thu, 1 Jul 2021 12:50:04 +0000 (14:50 +0200)
committerMark Wielaard <mark@klomp.org>
Thu, 1 Jul 2021 12:50:04 +0000 (14:50 +0200)
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

index c6975b2ed964cc4e4b14d90bf4dec02451102323..7fcaa6aa1d21c368c18f8a41cc60b1cf6fb14126 100644 (file)
@@ -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
This page took 0.044688 seconds and 5 git commands to generate.