From: Mark Wielaard Date: Tue, 1 Dec 2015 14:55:08 +0000 (+0100) Subject: tests: Fix some memory leaks in testcases. X-Git-Tag: elfutils-0.165~37 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a1372e06a04bad29e8c3c79d95497a8e381f823f;p=thirdparty%2Felfutils.git tests: Fix some memory leaks in testcases. Make sure all structures allocated in the testcases are disposed so running them under valgrind will show no memory leaks. Signed-off-by: Mark Wielaard --- diff --git a/tests/ChangeLog b/tests/ChangeLog index 69a25fc6e..4c56400cf 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,15 @@ +2015-12-01 Mark Wielaard + + * test-flag-nobits.c (main): Call elf_end. + * rerequest_tag.c (main): Call dwarf_end. + * funcscopes.c (handle_function): Free scopes. + * dwarf-getstring.c (main): Call dwarf_end. + * allregs.c (main): Free state.info. + * alldts.c (main): Free dyn. + * addrcfi.c (handle_address): Free stuff.frame between handle_cfi + calls. + * addrscopes.c (handle_address): Free scopes. + 2015-10-16 Mark Wielaard * Makefile.am [BUILD_STATIC] (libdw): Add -lz. diff --git a/tests/addrcfi.c b/tests/addrcfi.c index eb950c0be..589b8513c 100644 --- a/tests/addrcfi.c +++ b/tests/addrcfi.c @@ -160,10 +160,19 @@ handle_address (GElf_Addr pc, Dwfl *dwfl) Dwfl_Module *mod = dwfl_addrmodule (dwfl, pc); struct stuff stuff; - return (handle_cfi (dwfl, ".eh_frame", - dwfl_module_eh_cfi (mod, &stuff.bias), pc, &stuff) - & handle_cfi (dwfl, ".debug_frame", - dwfl_module_dwarf_cfi (mod, &stuff.bias), pc, &stuff)); + stuff.frame = NULL; + stuff.bias = 0; + int res = handle_cfi (dwfl, ".eh_frame", + dwfl_module_eh_cfi (mod, &stuff.bias), pc, &stuff); + free (stuff.frame); + + stuff.frame = NULL; + stuff.bias = 0; + res &= handle_cfi (dwfl, ".debug_frame", + dwfl_module_dwarf_cfi (mod, &stuff.bias), pc, &stuff); + free (stuff.frame); + + return res; } int diff --git a/tests/addrscopes.c b/tests/addrscopes.c index 2285d2ca9..791569f51 100644 --- a/tests/addrscopes.c +++ b/tests/addrscopes.c @@ -134,6 +134,7 @@ handle_address (GElf_Addr pc, Dwfl *dwfl) print_vars (indent + INDENT, die); } + free (scopes); } } diff --git a/tests/alldts.c b/tests/alldts.c index c39b8fb61..eaecaf573 100644 --- a/tests/alldts.c +++ b/tests/alldts.c @@ -256,6 +256,9 @@ main (void) /* And the data allocated in the .shstrtab section. */ free (data->d_buf); + /* And the dynamic entries. */ + free (dyn); + /* All done. */ if (elf_end (elf) != 0) { diff --git a/tests/allregs.c b/tests/allregs.c index 901d4e886..286f7e3cd 100644 --- a/tests/allregs.c +++ b/tests/allregs.c @@ -184,6 +184,7 @@ main (int argc, char **argv) dwarf_encoding_string (state.info[i].type), state.info[i].bits); } + free (state.info); } else do diff --git a/tests/dwarf-getstring.c b/tests/dwarf-getstring.c index 824edef87..ffa3e375a 100644 --- a/tests/dwarf-getstring.c +++ b/tests/dwarf-getstring.c @@ -70,6 +70,7 @@ main (int argc, char *argv[]) offset += len + 1; } + dwarf_end (dbg); close (fd); } diff --git a/tests/funcscopes.c b/tests/funcscopes.c index 55cb4facd..9c9018583 100644 --- a/tests/funcscopes.c +++ b/tests/funcscopes.c @@ -162,6 +162,7 @@ handle_function (Dwarf_Die *funcdie, void *arg) print_vars (indent + INDENT, die); } + free (scopes); } return 0; diff --git a/tests/rerequest_tag.c b/tests/rerequest_tag.c index d0bf5f24a..b4d46271a 100644 --- a/tests/rerequest_tag.c +++ b/tests/rerequest_tag.c @@ -42,5 +42,6 @@ main (int argc, char **argv) assert (die == &die_mem); assert (dwarf_tag (die) == 0); + dwarf_end (dw); return 0; } diff --git a/tests/test-flag-nobits.c b/tests/test-flag-nobits.c index ff19ce202..15d44ea8c 100644 --- a/tests/test-flag-nobits.c +++ b/tests/test-flag-nobits.c @@ -36,4 +36,7 @@ main (int argc, char **argv) Elf_Scn *scn = NULL; while ((scn = elf_nextscn (stripped, scn)) != NULL) elf_flagdata (elf_getdata (scn, NULL), ELF_C_SET, ELF_F_DIRTY); + + elf_end (stripped); + return 0; }