PR26539, memory leak in inflate.c
authorAlan Modra <amodra@gmail.com>
Fri, 15 Jan 2021 05:32:52 +0000 (16:02 +1030)
committerAlan Modra <amodra@gmail.com>
Fri, 15 Jan 2021 05:56:55 +0000 (16:26 +1030)
Like the PR15356 fix for the same leak in bfd, but for readelf.c

PR 26539
* readelf.c (uncompress_section_contents): Always call inflateEnd.

binutils/ChangeLog
binutils/readelf.c

index f099429d9b811b8922ce97abff44923ae3bd7883..0e3ae10c8ac9480e0b234c0028f0598ac005a65b 100644 (file)
@@ -1,3 +1,8 @@
+2021-01-15  Alan Modra  <amodra@gmail.com>
+
+       PR 26539
+       * readelf.c (uncompress_section_contents): Always call inflateEnd.
+
 2021-01-14  Alexandre Oliva <oliva@gnu.org>
 
        * MAINTAINERS: Update my email address.
index ad16b4571c9717effc3b955cba43c85332e81778..d828d5636df0b6172ab07ac6828e808fc521d225 100644 (file)
@@ -14221,15 +14221,15 @@ uncompress_section_contents (unsigned char **   buffer,
   while (strm.avail_in > 0)
     {
       if (rc != Z_OK)
-        goto fail;
+        break;
       strm.next_out = ((Bytef *) uncompressed_buffer
                        + (uncompressed_size - strm.avail_out));
       rc = inflate (&strm, Z_FINISH);
       if (rc != Z_STREAM_END)
-        goto fail;
+        break;
       rc = inflateReset (& strm);
     }
-  rc = inflateEnd (& strm);
+  rc |= inflateEnd (& strm);
   if (rc != Z_OK
       || strm.avail_out != 0)
     goto fail;