This is the mail archive of the elfutils-devel@sourceware.org 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] 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>
---
 tests/ChangeLog          | 12 ++++++++++++
 tests/addrcfi.c          | 17 +++++++++++++----
 tests/addrscopes.c       |  1 +
 tests/alldts.c           |  3 +++
 tests/allregs.c          |  1 +
 tests/dwarf-getstring.c  |  1 +
 tests/funcscopes.c       |  1 +
 tests/rerequest_tag.c    |  1 +
 tests/test-flag-nobits.c |  3 +++
 9 files changed, 36 insertions(+), 4 deletions(-)

diff --git a/tests/ChangeLog b/tests/ChangeLog
index 69a25fc..4c56400 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 eb950c0..589b851 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 2285d2c..791569f 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 c39b8fb..eaecaf5 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 901d4e8..286f7e3 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 824edef..ffa3e37 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 55cb4fa..9c90185 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 d0bf5f2..b4d4627 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 ff19ce2..15d44ea 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;
 }
-- 
2.5.0

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