]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
nm: Fix typo in size check to determine whether we stack allocated memory.
authorMark Wielaard <mjw@redhat.com>
Thu, 18 Jun 2015 09:07:41 +0000 (11:07 +0200)
committerMark Wielaard <mjw@redhat.com>
Fri, 19 Jun 2015 10:33:27 +0000 (12:33 +0200)
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 <mjw@redhat.com>
src/ChangeLog
src/nm.c

index 3d7761f9da84e5241da0ac86d15aa446b30be240..dbd1e44e9e6b9f42e7c54f84d46ca205720972a7 100644 (file)
@@ -1,3 +1,8 @@
+2015-06-18  Mark Wielaard  <mjw@redhat.com>
+
+       * 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  <mjw@redhat.com>
 
        * strings.c (readelf): Use "<unknown>" if we cannot retrieve section
index 8d1971582cc37693afbf0a2f81188845d0897e35..7339506975ff253dcce80de2f93da03c1c8db098 100644 (file)
--- 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);