From: Mark Wielaard Date: Thu, 18 Jun 2015 09:07:41 +0000 (+0200) Subject: nm: Fix typo in size check to determine whether we stack allocated memory. X-Git-Tag: elfutils-0.163~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9beaa94e56fb8b717f838e02905e100647138bf9;p=thirdparty%2Felfutils.git nm: Fix typo in size check to determine whether we stack allocated memory. We allocate GElf_SymX entries, which are larger than plain GElf_Sym structs. The check to see whether we could use stack allocation used the correct sizeof (GElf_SymX), but the check to see if we needed to free was using the incorrect sizeof (GElf_Sym). Which could cause us to leak memory. Signed-off-by: Mark Wielaard --- diff --git a/src/ChangeLog b/src/ChangeLog index 3d7761f9d..dbd1e44e9 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2015-06-18 Mark Wielaard + + * nm.c (show_symbols): Check sizeof (sym_mem[0]), not GElf_Sym to + known whether or not we stack allocated memory. + 2015-06-18 Mark Wielaard * strings.c (readelf): Use "" if we cannot retrieve section diff --git a/src/nm.c b/src/nm.c index 8d1971582..733950697 100644 --- a/src/nm.c +++ b/src/nm.c @@ -1383,7 +1383,7 @@ show_symbols (Ebl *ebl, GElf_Ehdr *ehdr, Elf_Scn *scn, Elf_Scn *xndxscn, } /* Free all memory. */ - if (nentries * sizeof (GElf_Sym) >= MAX_STACK_ALLOC) + if (nentries * sizeof (sym_mem[0]) >= MAX_STACK_ALLOC) free (sym_mem); obstack_free (&whereob, NULL);