From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5472 invoked by alias); 10 Nov 2008 19:37:57 -0000 Received: (qmail 5453 invoked by uid 22791); 10 Nov 2008 19:37:56 -0000 X-Spam-Check-By: sourceware.org Received: from mx2.redhat.com (HELO mx2.redhat.com) (66.187.237.31) by sourceware.org (qpsmtpd/0.31) with ESMTP; Mon, 10 Nov 2008 19:37:20 +0000 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id mAAJbBMT007320 for ; Mon, 10 Nov 2008 14:37:11 -0500 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id mAAJbAft018716; Mon, 10 Nov 2008 14:37:10 -0500 Received: from opsy.redhat.com (vpn-13-202.rdu.redhat.com [10.11.13.202]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id mAAJb9Xf023573; Mon, 10 Nov 2008 14:37:09 -0500 Received: by opsy.redhat.com (Postfix, from userid 500) id 22A493786D6; Mon, 10 Nov 2008 12:37:09 -0700 (MST) To: gdb-patches@sourceware.org Subject: RFA: fix memory leak in "source" command From: Tom Tromey Reply-To: Tom Tromey X-Attribution: Tom Date: Mon, 10 Nov 2008 19:45:00 -0000 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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: 2008-11/txt/msg00187.txt.bz2 Valgrind pointed out that the "source" command leaks full_pathname. The fix is to add a cleanup for it. This patch also makes sure to run the cleanups on early return from the function. Built and regested on x86-64 (compile farm). Ok? Tom :ADDPATCH cli: 2008-11-10 Tom Tromey * cli/cli-cmds.c (source_script): Clean up full_pathname. Run cleanups on early return. diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c index d9d2c56..21a64a0 100644 --- a/gdb/cli/cli-cmds.c +++ b/gdb/cli/cli-cmds.c @@ -450,6 +450,7 @@ source_script (char *file, int from_tty) files. Put the full location in 'full_pathname'. */ fd = openp (source_path, OPF_TRY_CWD_FIRST, file, O_RDONLY, 0, &full_pathname); + make_cleanup (xfree, full_pathname); /* Use the full path name, if it is found. */ if (full_pathname != NULL && fd != -1) @@ -462,7 +463,10 @@ source_script (char *file, int from_tty) if (from_tty) perror_with_name (file); else - return; + { + do_cleanups (old_cleanups); + return; + } } stream = fdopen (fd, FOPEN_RT);