This is the mail archive of the mailing list for the elfutils project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] 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 <>
 src/ChangeLog | 5 +++++
 src/nm.c      | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index 7c47079..1b4f1d6 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,10 @@
 2015-06-18  Mark Wielaard  <>
+	* nm.c (show_symbols): Check sizeof (GElf_SymX), not GElf_Sym to
+	known whether or not we stack allocated memory.
+2015-06-18  Mark Wielaard  <>
 	* strings.c (readelf): Use "<unknown>" if we cannot retrieve section
diff --git a/src/nm.c b/src/nm.c
index 8d19715..d89bdc7 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 (GElf_SymX) >= MAX_STACK_ALLOC)
     free (sym_mem);
   obstack_free (&whereob, NULL);

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]