From: Mark Wielaard Date: Fri, 24 Apr 2020 23:21:12 +0000 (+0200) Subject: libelf: Fix double free in __libelf_compress on error path. X-Git-Tag: elfutils-0.180~19 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a5d73b3e51afada171da9781089cd0e8fc9f64a6;p=thirdparty%2Felfutils.git libelf: Fix double free in __libelf_compress on error path. 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 --- diff --git a/libelf/ChangeLog b/libelf/ChangeLog index 8f79a6252..56f5354c5 100644 --- a/libelf/ChangeLog +++ b/libelf/ChangeLog @@ -1,3 +1,7 @@ +2020-04-25 Mark Wielaard + + * elf_compress.c (__libelf_compress): Remove free (out_buf). + 2020-03-18 Omar Sandoval * elf_getphdrnum.c (__elf_getphdrnum_rdlock): Call diff --git a/libelf/elf_compress.c b/libelf/elf_compress.c index b1b896890..e5d3d2e09 100644 --- a/libelf/elf_compress.c +++ b/libelf/elf_compress.c @@ -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); }