From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12182 invoked by alias); 30 Apr 2009 06:38:47 -0000 Received: (qmail 12172 invoked by uid 22791); 30 Apr 2009 06:38:46 -0000 X-SWARE-Spam-Status: No, hits=-2.2 required=5.0 tests=AWL,BAYES_00,SPF_PASS X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (216.239.45.13) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 30 Apr 2009 06:38:41 +0000 Received: from spaceape12.eur.corp.google.com (spaceape12.eur.corp.google.com [172.28.16.146]) by smtp-out.google.com with ESMTP id n3U6cdCU008590 for ; Wed, 29 Apr 2009 23:38:39 -0700 Received: from localhost (ruffy.mtv.corp.google.com [172.18.118.116]) by spaceape12.eur.corp.google.com with ESMTP id n3U6cbpa019057 for ; Wed, 29 Apr 2009 23:38:38 -0700 Received: by localhost (Postfix, from userid 67641) id 08D4384890; Wed, 29 Apr 2009 23:38:36 -0700 (PDT) To: gdb-patches@sourceware.org Subject: [RFA] Fix memory leak in gdbserver Message-Id: <20090430063837.08D4384890@localhost> Date: Thu, 30 Apr 2009 06:38:00 -0000 From: dje@google.com (Doug Evans) X-System-Of-Record: true X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2009-04/txt/msg00803.txt.bz2 Hi. This fixes a memory leak in gdbserver. Ok to check in? 2009-04-29 Doug Evans * 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;