From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2250 invoked by alias); 1 Aug 2006 16:07:10 -0000 Received: (qmail 2194 invoked by uid 22791); 1 Aug 2006 16:07:07 -0000 X-Spam-Check-By: sourceware.org Received: from ip-160-218-140-54.eurotel.cz (HELO host0.dyn.jankratochvil.net) (160.218.140.54) by sourceware.org (qpsmtpd/0.31) with ESMTP; Tue, 01 Aug 2006 16:07:01 +0000 Received: from host0.dyn.jankratochvil.net (localhost [127.0.0.1]) by host0.dyn.jankratochvil.net (8.13.7/8.13.7) with ESMTP id k71G6seA008555 for ; Tue, 1 Aug 2006 18:06:55 +0200 Received: (from lace@localhost) by host0.dyn.jankratochvil.net (8.13.7/8.13.7/Submit) id k71G6rSH008554 for gdb-patches@sourceware.org; Tue, 1 Aug 2006 18:06:53 +0200 Date: Tue, 01 Aug 2006 16:07:00 -0000 From: Jan Kratochvil To: gdb-patches@sourceware.org Subject: [patch] Fix memory leak on bfd_close(BFD_IN_MEMORY) Message-ID: <20060801160653.GA8511@host0.dyn.jankratochvil.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="BOKacYhQ+x31HxR3" Content-Disposition: inline User-Agent: Mutt/1.4.2.1i Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2006-08/txt/msg00012.txt.bz2 --BOKacYhQ+x31HxR3 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 978 Hi, I feel the patch 2004-10-24 Daniel Jacobowitz * opncls.c (bfd_close): Return TRUE for BFD_IN_MEMORY. Index: opncls.c =================================================================== RCS file: /cvs/src/src/bfd/opncls.c,v retrieving revision 1.25 retrieving revision 1.26 diff -u -p -r1.25 -r1.26 --- opncls.c 10 Oct 2004 13:58:05 -0000 1.25 +++ opncls.c 24 Oct 2004 18:45:38 -0000 1.26 @@ -598,7 +598,7 @@ bfd_close (bfd *abfd) if (!(abfd->flags & BFD_IN_MEMORY)) ret = abfd->iovec->bclose (abfd); else - ret = 0; + ret = TRUE; /* If the file was open for writing and is now executable, make it so. */ introduced a memory leak. This codepath occurs only on ia64 on the second run: (gdb) run (gdb) run Attached patch which IMO fixes the leak and it does not crash (although it was not ElectricFence-d) on ia64. Maybe not worth it (yes, the proper function set should be implemented etc.). Regards, Jan Kratochvil --BOKacYhQ+x31HxR3 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="gdb-6.5.50.20060801-bfd_close-BFD_IN_MEMORY.patch" Content-length: 1531 https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=200402 diff -ru gdb-6.3-orig/bfd/opncls.c gdb-6.3/bfd/opncls.c --- gdb-6.3-orig/bfd/opncls.c 2006-07-28 04:56:05.000000000 -0400 +++ gdb-6.3/bfd/opncls.c 2006-07-28 04:56:25.000000000 -0400 @@ -595,27 +595,36 @@ /* FIXME: cagney/2004-02-15: Need to implement a BFD_IN_MEMORY io vector. */ - if (!(abfd->flags & BFD_IN_MEMORY)) - ret = abfd->iovec->bclose (abfd); - else - ret = TRUE; + if (abfd->flags & BFD_IN_MEMORY) + { + struct bfd_in_memory *bim = abfd->iostream; - /* If the file was open for writing and is now executable, - make it so. */ - if (ret - && abfd->direction == write_direction - && abfd->flags & EXEC_P) + free (bim->buffer); + free (bim); + + ret = TRUE; + } + else { - struct stat buf; + ret = abfd->iovec->bclose (abfd); - if (stat (abfd->filename, &buf) == 0) + /* If the file was open for writing and is now executable, + make it so. */ + if (ret + && abfd->direction == write_direction + && abfd->flags & EXEC_P) { - unsigned int mask = umask (0); + struct stat buf; - umask (mask); - chmod (abfd->filename, - (0777 - & (buf.st_mode | ((S_IXUSR | S_IXGRP | S_IXOTH) &~ mask)))); + if (stat (abfd->filename, &buf) == 0) + { + unsigned int mask = umask (0); + + umask (mask); + chmod (abfd->filename, + (0777 + & (buf.st_mode | ((S_IXUSR | S_IXGRP | S_IXOTH) &~ mask)))); + } } } --BOKacYhQ+x31HxR3--