This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB 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]

[RFA] Cleanup some memory leaks


Hi,

Recently, I've been checking for memory leaks in some code, and I ran across these (reported by valgrind).

Okay?
Keith

ChangeLog
2012-05-23  Keith Seitz  <keiths@redhat.com>

	* linespec.c (decode_objc): Add cleanup to free
	INFO.FILE_SYMTABS.
	(find_linespec_symbols): Add cleanup to free CLASSES.
	* symfile.c (find_separate_debug_file_by_debuglink): Add
	cleanup to free DEBUGLINK.
	* ui-out.c (clear_header_list): No need to check if
	HEADER_NEXT.COLHDR is NULL.
	Free HEADER_NEXT.COL_NAME.
Index: linespec.c
===================================================================
RCS file: /cvs/src/src/gdb/linespec.c,v
retrieving revision 1.156
diff -u -p -r1.156 linespec.c
--- linespec.c	18 May 2012 21:02:48 -0000	1.156
+++ linespec.c	23 May 2012 19:01:48 -0000
@@ -2409,6 +2409,7 @@ decode_objc (struct linespec_state *self
   info.state = self;
   info.file_symtabs = NULL;
   VEC_safe_push (symtab_p, info.file_symtabs, NULL);
+  make_cleanup (VEC_cleanup (symtab_p), &info.file_symtabs);
   info.result.symbols = NULL;
   info.result.minimal_symbols = NULL;
   values.nelts = 0;
@@ -2949,6 +2950,7 @@ find_linespec_symbols (struct linespec_s
 
   /* Find a list of classes named KLASS.  */
   classes = lookup_prefix_sym (state, file_symtabs, klass);
+  make_cleanup (VEC_cleanup (symbolp), &classes);
   if (!VEC_empty (symbolp, classes))
     {
       /* Now locate a list of suitable methods named METHOD.  */
Index: symfile.c
===================================================================
RCS file: /cvs/src/src/gdb/symfile.c,v
retrieving revision 1.332
diff -u -p -r1.332 symfile.c
--- symfile.c	18 May 2012 21:02:50 -0000	1.332
+++ symfile.c	23 May 2012 19:01:49 -0000
@@ -1553,8 +1553,9 @@ find_separate_debug_file_by_debuglink (s
       return NULL;
     }
 
+  cleanups = make_cleanup (xfree, debuglink);
   dir = xstrdup (objfile->name);
-  cleanups = make_cleanup (xfree, dir);
+  make_cleanup (xfree, dir);
   terminate_after_last_dir_separator (dir);
   canon_dir = lrealpath (dir);
 
Index: ui-out.c
===================================================================
RCS file: /cvs/src/src/gdb/ui-out.c,v
retrieving revision 1.60
diff -u -p -r1.60 ui-out.c
--- ui-out.c	27 Mar 2012 19:08:36 -0000	1.60
+++ ui-out.c	23 May 2012 19:01:49 -0000
@@ -968,8 +968,8 @@ clear_header_list (struct ui_out *uiout)
     {
       uiout->table.header_next = uiout->table.header_first;
       uiout->table.header_first = uiout->table.header_first->next;
-      if (uiout->table.header_next->colhdr != NULL)
-	xfree (uiout->table.header_next->colhdr);
+      xfree (uiout->table.header_next->colhdr);
+      xfree (uiout->table.header_next->col_name);
       xfree (uiout->table.header_next);
     }
   gdb_assert (uiout->table.header_first == NULL);

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