Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: dje@google.com (Doug Evans)
To: gdb-patches@sourceware.org
Subject: [RFA] Fix memory leak in gdbserver
Date: Thu, 30 Apr 2009 06:38:00 -0000	[thread overview]
Message-ID: <20090430063837.08D4384890@localhost> (raw)

Hi.

This fixes a memory leak in gdbserver.

Ok to check in?

2009-04-29  Doug Evans  <dje@google.com>

	* inferiors.c (remove_process): Fix memory leak, free process.
	* linux-low.c (linux_remove_process): New function.
	(linux_kill): Call it instead of remove_process.
	(linux_detach, linux_wait_1): Ditto.

Index: inferiors.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/inferiors.c,v
retrieving revision 1.20
diff -u -p -r1.20 inferiors.c
--- inferiors.c	3 Apr 2009 20:15:51 -0000	1.20
+++ inferiors.c	30 Apr 2009 01:23:29 -0000
@@ -427,12 +427,17 @@ add_process (int pid, int attached)
   return process;
 }
 
+/* Remove a process from the common process list and free the memory
+   allocated for it.
+   The caller is responsible for freeing private data first.  */
+
 void
 remove_process (struct process_info *process)
 {
   clear_symbol_cache (&process->symbol_cache);
   free_all_breakpoints (process);
   remove_inferior (&all_processes, &process->head);
+  free (process);
 }
 
 struct process_info *
Index: linux-low.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/linux-low.c,v
retrieving revision 1.97
diff -u -p -r1.97 linux-low.c
--- linux-low.c	3 Apr 2009 11:40:02 -0000	1.97
+++ linux-low.c	30 Apr 2009 06:30:01 -0000
@@ -182,6 +182,16 @@ linux_add_process (int pid, int attached
   return proc;
 }
 
+/* Remove a process from the common process list,
+   also freeing all private data.  */
+
+static void
+linux_remove_process (struct process_info *process)
+{
+  free (process->private);
+  remove_process (process);
+}
+
 /* Handle a GNU/Linux extended wait response.  If we see a clone
    event, we need to add the new LWP to our list (and not report the
    trap to higher layers).  */
@@ -565,7 +575,7 @@ linux_kill (int pid)
     } while (lwpid > 0 && WIFSTOPPED (wstat));
 
   delete_lwp (lwp);
-  remove_process (process);
+  linux_remove_process (process);
   return 0;
 }
 
@@ -654,7 +664,7 @@ linux_detach (int pid)
 
   delete_all_breakpoints ();
   find_inferior (&all_threads, linux_detach_one_lwp, &pid);
-  remove_process (process);
+  linux_remove_process (process);
   return 0;
 }
 
@@ -1273,7 +1283,7 @@ retry:
 	  struct process_info *process = find_process_pid (pid);
 
 	  delete_lwp (lwp);
-	  remove_process (process);
+	  linux_remove_process (process);
 
 	  current_inferior = NULL;
 


             reply	other threads:[~2009-04-30  6:38 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-30  6:38 Doug Evans [this message]
2009-04-30  9:28 ` Pedro Alves
2009-05-06  8:50   ` Build failure for x86_64-pc-mingw32 target Kai Tietz
2009-05-06  9:05     ` Hui Zhu
2009-05-06  9:37       ` Pedro Alves
2009-05-06 10:46         ` Hui Zhu
2009-05-06 11:20           ` Hui Zhu
2009-05-06 11:36             ` Kai Tietz
2009-05-06 16:03         ` [ARI] Add "bzero" (was: "Re: Build failure for x86_64-pc-mingw32 target") Joel Brobecker
2009-05-06 16:53           ` Joel Brobecker
2009-05-06 18:11           ` Eli Zaretskii
2009-05-06 18:37             ` Joel Brobecker
2009-05-18 19:24           ` [ARI] Add "bzero" Tom Tromey
2009-05-20  5:19             ` Joel Brobecker
2009-05-21  0:27             ` Joel Brobecker
2009-05-27 18:15               ` Tom Tromey
2009-05-06 10:19       ` Build failure for x86_64-pc-mingw32 target Mark Kettenis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090430063837.08D4384890@localhost \
    --to=dje@google.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox