From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13393 invoked by alias); 17 Mar 2014 16:02:17 -0000 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 Received: (qmail 13381 invoked by uid 89); 17 Mar 2014 16:02:16 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.3.2 X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 17 Mar 2014 16:02:16 +0000 Received: from svr-orw-fem-01.mgc.mentorg.com ([147.34.98.93]) by relay1.mentorg.com with esmtp id 1WPZzQ-0007TD-Na from Hui_Zhu@mentor.com for gdb-patches@sourceware.org; Mon, 17 Mar 2014 09:02:12 -0700 Received: from SVR-ORW-FEM-05.mgc.mentorg.com ([147.34.97.43]) by svr-orw-fem-01.mgc.mentorg.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.4675); Mon, 17 Mar 2014 09:02:12 -0700 Received: from localhost.localdomain (147.34.91.1) by svr-orw-fem-05.mgc.mentorg.com (147.34.97.43) with Microsoft SMTP Server id 14.2.247.3; Mon, 17 Mar 2014 09:00:26 -0700 Message-ID: <53271C80.1040103@mentor.com> Date: Mon, 17 Mar 2014 16:02:00 -0000 From: Hui Zhu User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.3.0 MIME-Version: 1.0 To: gdb-patches ml Subject: [PATCH 1/1] Fix memleak of the pid_to_exec_file target_ops method for some platforms References: <53271C09.5000709@mentor.com> In-Reply-To: <53271C09.5000709@mentor.com> Content-Type: text/plain; charset="ISO-8859-1"; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2014-03/txt/msg00375.txt.bz2 I said most of the pid_to_exec_file target_ops method for some platforms will allocate memory for exec_file and add them to cleanup. But some of them didn't do that. So I make a patch to fix this memleak. Thanks, Hui 2014-03-17 Hui Zhu * fbsd-nat.c (fbsd_pid_to_exec_file): Add make_cleanup. * nbsd-nat.c (nbsd_pid_to_exec_file): Ditto. --- a/gdb/fbsd-nat.c +++ b/gdb/fbsd-nat.c @@ -43,6 +43,8 @@ fbsd_pid_to_exec_file (struct target_ops char *buf = xcalloc (len, sizeof (char)); char *path; + make_cleanup (xfree, buf); + #ifdef KERN_PROC_PATHNAME int mib[4]; --- a/gdb/nbsd-nat.c +++ b/gdb/nbsd-nat.c @@ -31,6 +31,8 @@ nbsd_pid_to_exec_file (struct target_ops char *buf = xcalloc (len, sizeof (char)); char *path; + make_cleanup (xfree, buf); + path = xstrprintf ("/proc/%d/exe", pid); if (readlink (path, buf, PATH_MAX - 1) == -1) {