summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Wielaard <mjw@redhat.com>2015-12-01 15:55:08 +0100
committerMark Wielaard <mjw@redhat.com>2016-01-02 20:37:44 +0100
commita1372e06a04bad29e8c3c79d95497a8e381f823f (patch)
treeb03cad8fba9772ba5f3524fcf40e3829b6c7c1af
parentdb30f8b21993c09339c5bced7b0827eedf8d4fef (diff)
downloadelfutils-a1372e06a04bad29e8c3c79d95497a8e381f823f.tar.gz
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>
-rw-r--r--tests/ChangeLog12
-rw-r--r--tests/addrcfi.c17
-rw-r--r--tests/addrscopes.c1
-rw-r--r--tests/alldts.c3
-rw-r--r--tests/allregs.c1
-rw-r--r--tests/dwarf-getstring.c1
-rw-r--r--tests/funcscopes.c1
-rw-r--r--tests/rerequest_tag.c1
-rw-r--r--tests/test-flag-nobits.c3
9 files changed, 36 insertions, 4 deletions
diff --git a/tests/ChangeLog b/tests/ChangeLog
index 69a25fc6..4c56400c 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -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.
diff --git a/tests/addrcfi.c b/tests/addrcfi.c
index eb950c0b..589b8513 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 2285d2ca..791569f5 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 c39b8fb6..eaecaf57 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 901d4e88..286f7e3c 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 824edef8..ffa3e375 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 55cb4fac..9c901858 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 d0bf5f24..b4d46271 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 ff19ce20..15d44ea8 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;
}