From mboxrd@z Thu Jan 1 00:00:00 1970 Content-Type: multipart/mixed; boundary="===============5647492913754887149==" MIME-Version: 1.0 From: Mark Wielaard To: elfutils-devel@lists.fedorahosted.org Subject: [PATCH] libelf: Fix memory leak when zlib deflateInit fails in elf_compress. Date: Thu, 14 Apr 2016 21:11:59 +0200 Message-ID: <1460661119-1309-1-git-send-email-mjw@redhat.com> --===============5647492913754887149== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable On error we return NULL, not out_buf. So make sure to not leak it. Signed-off-by: Mark Wielaard --- libelf/ChangeLog | 5 +++++ libelf/elf_compress.c | 1 + 2 files changed, 6 insertions(+) diff --git a/libelf/ChangeLog b/libelf/ChangeLog index 350e4eb..668687d 100644 --- a/libelf/ChangeLog +++ b/libelf/ChangeLog @@ -1,3 +1,8 @@ +2016-04-14 Mark Wielaard + + * elf_compress.c (__libelf_compress): Free out_buf if deflateInit + fails. + 2016-02-13 Mark Wielaard = * elf32_updatefile.c (updatemmap): Free scns when out of memory. diff --git a/libelf/elf_compress.c b/libelf/elf_compress.c index 4c7c35e..10574ea 100644 --- a/libelf/elf_compress.c +++ b/libelf/elf_compress.c @@ -117,6 +117,7 @@ __libelf_compress (Elf_Scn *scn, size_t hsize, int ei_d= ata, int zrc =3D deflateInit (&z, Z_BEST_COMPRESSION); if (zrc !=3D Z_OK) { + free (out_buf); __libelf_seterrno (ELF_E_COMPRESS_ERROR); return NULL; } -- = 2.5.5 --===============5647492913754887149==--