libelf: Fix double free in __libelf_compress on error path.
authorMark Wielaard <mark@klomp.org>
Fri, 24 Apr 2020 23:21:12 +0000 (01:21 +0200)
committerMark Wielaard <mark@klomp.org>
Fri, 24 Apr 2020 23:26:48 +0000 (01:26 +0200)
In commit 2092865a7e589ff805caa47e69ac9630f34d4f2a
"libelf: {de,}compress: ensure zlib resource cleanup" we added a
call to deflate_cleanup to make sure all resources were freed.
As GCC10 -fanalyzer points out that could cause a double free
of out_buf. Fix by removing the free (out_buf) in __libelf_compress.

Signed-off-by: Mark Wielaard <mark@klomp.org>
libelf/ChangeLog
libelf/elf_compress.c

index 8f79a62..56f5354 100644 (file)
@@ -1,3 +1,7 @@
+2020-04-25  Mark Wielaard  <mark@klomp.org>
+
+       * elf_compress.c (__libelf_compress): Remove free (out_buf).
+
 2020-03-18  Omar Sandoval  <osandov@fb.com>
 
        * elf_getphdrnum.c (__elf_getphdrnum_rdlock): Call
index b1b8968..e5d3d2e 100644 (file)
@@ -113,7 +113,6 @@ __libelf_compress (Elf_Scn *scn, size_t hsize, int ei_data,
   int zrc = deflateInit (&z, Z_BEST_COMPRESSION);
   if (zrc != Z_OK)
     {
-      free (out_buf);
       __libelf_seterrno (ELF_E_COMPRESS_ERROR);
       return deflate_cleanup(NULL, NULL);
     }