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 <mjw@redhat.com>
This commit is contained in:
Mark Wielaard
2015-12-01 15:55:08 +01:00
parent db30f8b219
commit a1372e06a0
9 changed files with 36 additions and 4 deletions
+12
View File
@@ -1,3 +1,15 @@
2015-12-01 Mark Wielaard <mjw@redhat.com>
* 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 <mjw@redhat.com>
* Makefile.am [BUILD_STATIC] (libdw): Add -lz.
+13 -4
View File
@@ -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
+1
View File
@@ -134,6 +134,7 @@ handle_address (GElf_Addr pc, Dwfl *dwfl)
print_vars (indent + INDENT, die);
}
free (scopes);
}
}
+3
View File
@@ -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)
{
+1
View File
@@ -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
+1
View File
@@ -70,6 +70,7 @@ main (int argc, char *argv[])
offset += len + 1;
}
dwarf_end (dbg);
close (fd);
}
+1
View File
@@ -162,6 +162,7 @@ handle_function (Dwarf_Die *funcdie, void *arg)
print_vars (indent + INDENT, die);
}
free (scopes);
}
return 0;
+1
View File
@@ -42,5 +42,6 @@ main (int argc, char **argv)
assert (die == &die_mem);
assert (dwarf_tag (die) == 0);
dwarf_end (dw);
return 0;
}
+3
View File
@@ -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;
}