Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [RFA] Fix memory leak in lookup_symtab
@ 2011-05-11  4:00 Thiago Jung Bauermann
  2011-05-11 14:17 ` Tom Tromey
  0 siblings, 1 reply; 3+ messages in thread
From: Thiago Jung Bauermann @ 2011-05-11  4:00 UTC (permalink / raw)
  To: gdb-patches ml

Hi,

While working on the patch I just posted, I found this memory leak (I
actually found more, but this was trivial to fix). It doesn't seem big,
leaks at most 890 bytes in break.exp. I didn't check with other
testcases.

No regressions on ppc-linux and ppc64-linux. Ok?
-- 
[]'s
Thiago Jung Bauermann
IBM Linux Technology Center


2011-05-11  Thiago Jung Bauermann  <bauerman@br.ibm.com>

	* symtab.c (lookup_symtab): Run cleanup before returning.

diff --git a/gdb/symtab.c b/gdb/symtab.c
index d98ac57..f6dc0e9 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -158,6 +158,9 @@ lookup_symtab (const char *name)
   struct objfile *objfile;
   char *real_path = NULL;
   char *full_path = NULL;
+  struct cleanup *cleanup;
+
+  cleanup = make_cleanup (null_cleanup, NULL);
 
   /* Here we are interested in canonicalizing an absolute path, not
      absolutizing a relative path.  */
@@ -177,6 +180,7 @@ got_symtab:
   {
     if (FILENAME_CMP (name, s->filename) == 0)
       {
+	do_cleanups (cleanup);
 	return s;
       }
 
@@ -189,6 +193,7 @@ got_symtab:
 
         if (fp != NULL && FILENAME_CMP (full_path, fp) == 0)
           {
+	    do_cleanups (cleanup);
             return s;
           }
       }
@@ -204,6 +209,7 @@ got_symtab:
             make_cleanup (xfree, rp);
             if (FILENAME_CMP (real_path, rp) == 0)
               {
+		do_cleanups (cleanup);
                 return s;
               }
           }
@@ -216,7 +222,10 @@ got_symtab:
     ALL_SYMTABS (objfile, s)
     {
       if (FILENAME_CMP (lbasename (s->filename), name) == 0)
-	return s;
+	{
+	  do_cleanups (cleanup);
+	  return s;
+	}
     }
 
   /* Same search rules as above apply here, but now we look thru the
@@ -235,9 +244,15 @@ got_symtab:
   }
 
   if (s != NULL)
-    return s;
+    {
+      do_cleanups (cleanup);
+      return s;
+    }
   if (!found)
-    return NULL;
+    {
+      do_cleanups (cleanup);
+      return NULL;
+    }
 
   /* At this point, we have located the psymtab for this file, but
      the conversion to a symtab has failed.  This usually happens



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [RFA] Fix memory leak in lookup_symtab
  2011-05-11  4:00 [RFA] Fix memory leak in lookup_symtab Thiago Jung Bauermann
@ 2011-05-11 14:17 ` Tom Tromey
  2011-05-11 18:30   ` Thiago Jung Bauermann
  0 siblings, 1 reply; 3+ messages in thread
From: Tom Tromey @ 2011-05-11 14:17 UTC (permalink / raw)
  To: Thiago Jung Bauermann; +Cc: gdb-patches ml

>>>>> "Thiago" == Thiago Jung Bauermann <bauerman@br.ibm.com> writes:

Thiago> 2011-05-11  Thiago Jung Bauermann  <bauerman@br.ibm.com>
Thiago> 	* symtab.c (lookup_symtab): Run cleanup before returning.

Ok.
Thanks for doing this.

Tom


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [RFA] Fix memory leak in lookup_symtab
  2011-05-11 14:17 ` Tom Tromey
@ 2011-05-11 18:30   ` Thiago Jung Bauermann
  0 siblings, 0 replies; 3+ messages in thread
From: Thiago Jung Bauermann @ 2011-05-11 18:30 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches ml

On Wed, 2011-05-11 at 08:17 -0600, Tom Tromey wrote:
> >>>>> "Thiago" == Thiago Jung Bauermann <bauerman@br.ibm.com> writes:
> 
> Thiago> 2011-05-11  Thiago Jung Bauermann  <bauerman@br.ibm.com>
> Thiago> 	* symtab.c (lookup_symtab): Run cleanup before returning.
> 
> Ok.
> Thanks for doing this.

Committed. Thanks!
-- 
[]'s
Thiago Jung Bauermann
IBM Linux Technology Center


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-05-11 18:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-11  4:00 [RFA] Fix memory leak in lookup_symtab Thiago Jung Bauermann
2011-05-11 14:17 ` Tom Tromey
2011-05-11 18:30   ` Thiago Jung Bauermann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox