From patchwork Mon Mar 17 16:02:08 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hui Zhu X-Patchwork-Id: 125 Return-Path: X-Original-To: siddhesh@wilcox.dreamhost.com Delivered-To: siddhesh@wilcox.dreamhost.com Received: from homiemail-mx23.g.dreamhost.com (caibbdcaabja.dreamhost.com [208.113.200.190]) by wilcox.dreamhost.com (Postfix) with ESMTP id 3ED913600D3 for ; Mon, 17 Mar 2014 09:02:19 -0700 (PDT) Received: by homiemail-mx23.g.dreamhost.com (Postfix, from userid 14314964) id E513261C63919; Mon, 17 Mar 2014 09:02:18 -0700 (PDT) X-Original-To: gdb@patchwork.siddhesh.in Delivered-To: x14314964@homiemail-mx23.g.dreamhost.com Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by homiemail-mx23.g.dreamhost.com (Postfix) with ESMTPS id C235361C6EE38 for ; Mon, 17 Mar 2014 09:02:18 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:message-id:date:from:mime-version:to:subject :references:in-reply-to:content-type:content-transfer-encoding; q=dns; s=default; b=BQMXcHqNtcPR3lGM2AHcTKdIbFkFLb+tE7H6A7aCZHU yVxCPciwEHdcw5JT7fAvWlT0CvA98dLvhfd69Isvk6OVP7SA6GfvEtyg4xTW70jV 2ydDE/g2GXqpbBJbIUPwtXkEVQsQllOGrEKRIuveUc1BwSat/NnVOj7YdZqaBK4Y = DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:message-id:date:from:mime-version:to:subject :references:in-reply-to:content-type:content-transfer-encoding; s=default; bh=fHwJodjuxyMAabpI4Wzuv5Dd8uI=; b=ozAqVDcFcSBW1b5mj rJtul9qtsmm4TsiRyHmErUyaQBfxiMlM2mq9jgiYjgEgVAh+l8ybM/8BUlYJxAw5 JOl2mp4n0n9k+FaplO8SW4b1hNsVm6yhRqQh7hh8/6BFUYayKLKIz/TF2YTpITKx 4T3pUSw1WkzsxeoY5c1g6SoZSU= 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-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@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: Tue, 18 Mar 2014 00:02:08 +0800 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> X-IsSubscribed: yes X-DH-Original-To: gdb@patchwork.siddhesh.in 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) {