[PATCH] libelf: decompress: ensure zlib resource cleanup

Matthias Maennich maennich@google.com
Sun Mar 15 22:03:29 GMT 2020


__libelf_decompress would only cleanup zlib resources via inflateEnd()
in case inflating was successful, but would leak memory if not. Fix this
by calling inflateEnd() in the error case as well.

Fixes: 272018bba1f2 ("libelf: Add elf_compress and elf_compress_gnu.")
Signed-off-by: Matthias Maennich <maennich@google.com>
---
 libelf/elf_compress.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libelf/elf_compress.c b/libelf/elf_compress.c
index 244467b5e3ae..beb1834bbbd7 100644
--- a/libelf/elf_compress.c
+++ b/libelf/elf_compress.c
@@ -257,6 +257,7 @@ __libelf_decompress (void *buf_in, size_t size_in, size_t size_out)
   if (unlikely (zrc != Z_OK) || unlikely (z.avail_out != 0))
     {
       free (buf_out);
+      inflateEnd(&z);
       __libelf_seterrno (ELF_E_DECOMPRESS_ERROR);
       return NULL;
     }
-- 
2.25.1.481.gfbce0eb801-goog



More information about the Elfutils-devel mailing list