From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25500 invoked by alias); 30 Oct 2008 21:52:48 -0000 Received: (qmail 25259 invoked by uid 22791); 30 Oct 2008 21:52:47 -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; Thu, 30 Oct 2008 21:50:47 +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 m9UJg0us029149; Thu, 30 Oct 2008 15:42:00 -0400 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 m9UJfxdg018366; Thu, 30 Oct 2008 15:42:00 -0400 Received: from opsy.redhat.com (vpn-12-180.rdu.redhat.com [10.11.12.180]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id m9UJfwb4022784; Thu, 30 Oct 2008 15:41:59 -0400 Received: by opsy.redhat.com (Postfix, from userid 500) id 5C35D3786F5; Thu, 30 Oct 2008 13:41:58 -0600 (MDT) To: Pedro Alves Cc: gdb-patches@sourceware.org Subject: Re: RFA: open-related cleanup handling References: <200810291740.14621.pedro@codesourcery.com> From: Tom Tromey Reply-To: Tom Tromey X-Attribution: Tom Date: Thu, 30 Oct 2008 21:53:00 -0000 In-Reply-To: <200810291740.14621.pedro@codesourcery.com> (Pedro Alves's message of "Wed\, 29 Oct 2008 17\:40\:14 +0000") Message-ID: User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux) 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-10/txt/msg00713.txt.bz2 >>>>> "Pedro" == Pedro Alves writes: Pedro> I noticed that discarding a _close cleanup is currently leaking the Pedro> xmalloc'ed int used to hold the file descriptor. Fixing it should be a Pedro> matter of doing something similar to make_cleanup_restore_integer Pedro> (using make_my_cleanup2) from inside make_cleanup_close. Pedro> Would you like to take care of that while you have your hangs Pedro> dirty doing these cleaning ups? No problem. How about this? I used make_cleanup_dtor -- same difference though. Built & regtested on x86-64 (compile farm). What do you think of making make_my_cleanup and make_my_cleanup2 static? They aren't used outside of utils.c. Tom 2008-10-30 Tom Tromey * utils.c (make_cleanup_close): Use make_cleanup_dtor. (do_close_cleanup): Don't free 'fd'. diff --git a/gdb/utils.c b/gdb/utils.c index f9a5f19..26d7933 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -244,7 +244,6 @@ do_close_cleanup (void *arg) { int *fd = arg; close (*fd); - xfree (fd); } struct cleanup * @@ -252,7 +251,7 @@ make_cleanup_close (int fd) { int *saved_fd = xmalloc (sizeof (fd)); *saved_fd = fd; - return make_cleanup (do_close_cleanup, saved_fd); + return make_cleanup_dtor (do_close_cleanup, saved_fd, xfree); } /* Helper function which does the work for make_cleanup_fclose. */