From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1LlNRC-0005Rq-LW for mharc-grub-devel@gnu.org; Sun, 22 Mar 2009 09:10:02 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LlNRA-0005R0-Te for grub-devel@gnu.org; Sun, 22 Mar 2009 09:10:00 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LlNR5-0005Lj-3e for grub-devel@gnu.org; Sun, 22 Mar 2009 09:09:59 -0400 Received: from [199.232.76.173] (port=51485 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LlNR4-0005Lc-UU for grub-devel@gnu.org; Sun, 22 Mar 2009 09:09:54 -0400 Received: from fg-out-1718.google.com ([72.14.220.152]:16266) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LlNR4-0001ox-El for grub-devel@gnu.org; Sun, 22 Mar 2009 09:09:54 -0400 Received: by fg-out-1718.google.com with SMTP id 19so461529fgg.7 for ; Sun, 22 Mar 2009 06:09:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:subject:references:in-reply-to :content-type; bh=G5NHn+9v3oUFWduJo6Zmc1dm/+iLh+Av3dp18c7z1h0=; b=v1cg/yh5ymR1onArxzNr/QAXlEiXcGrLib8Gp5RAwobnxB6bpf9XwvgnjGYoHY4BuI QOjAZK8qesYQuuvgkl0rhVZwugVEVbKHmsmRtSRqcgD3Weubzo14ebcvXg0wm5q5ImWW 8oHtKnKYn9gxuXmwqigPdyVUP7P32MC2OYLmg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type; b=hRjkePGdsKD/A7MuTJEbs6UBfuLkAr3KgwTpfWcjSpVk8x8oyGcHo9AECd7sHFc/3r OIgAVu/w+jDcmdRv3gAz1dO7nbH8v9JsYI+71mmAtGDU2a4WUhnGJf4Sqoda61Vqix1s amJMxFObtSTxYwCZ4AHEsiosp/0lHptKe0RME= Received: by 10.86.53.11 with SMTP id b11mr2812555fga.76.1237727393346; Sun, 22 Mar 2009 06:09:53 -0700 (PDT) Received: from ?192.168.1.25? (252.80.3.213.cust.bluewin.ch [213.3.80.252]) by mx.google.com with ESMTPS id 12sm1733806fgg.27.2009.03.22.06.09.52 (version=SSLv3 cipher=RC4-MD5); Sun, 22 Mar 2009 06:09:52 -0700 (PDT) Message-ID: <49C638A0.3060506@gmail.com> Date: Sun, 22 Mar 2009 14:09:52 +0100 From: phcoder User-Agent: Thunderbird 2.0.0.21 (X11/20090318) MIME-Version: 1.0 To: The development of GRUB 2 References: <49B52C12.5080105@gmail.com> In-Reply-To: <49B52C12.5080105@gmail.com> Content-Type: multipart/mixed; boundary="------------000501050006070702050607" X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) Subject: Re: Leak fixes X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 22 Mar 2009 13:10:01 -0000 This is a multi-part message in MIME format. --------------000501050006070702050607 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Rediffed 2009-03-22 Vladimir Serbinenko Leak fixes * kern/disk.c (grub_disk_cache_store): Invalidate previous cache in case of collision * disk/scsi.c (grub_scsi_open): free scsi in case of error phcoder wrote: > Hello I discovered some memory leaks. Here is the fix > The main one was is that if a hash collision occurs new cache entry > overwrites the old one but the old one wasn't freed. When loading a big > file it was leaking huge amounts of memory > -- Regards Vladimir 'phcoder' Serbinenko --------------000501050006070702050607 Content-Type: text/x-patch; name="leakfixes.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="leakfixes.diff" diff --git a/disk/scsi.c b/disk/scsi.c index 75b92b4..319d8d6 100644 --- a/disk/scsi.c +++ b/disk/scsi.c @@ -255,6 +255,7 @@ grub_scsi_open (const char *name, grub_disk_t disk) scsi->name = grub_strdup (name); if (! scsi->name) { + grub_free (scsi); return grub_errno; } @@ -263,6 +264,7 @@ grub_scsi_open (const char *name, grub_disk_t disk) err = grub_scsi_inquiry (scsi); if (err) { + grub_free (scsi); grub_dprintf ("scsi", "inquiry failed\n"); return grub_errno; } @@ -275,6 +277,7 @@ grub_scsi_open (const char *name, grub_disk_t disk) if (scsi->devtype != grub_scsi_devtype_direct && scsi->devtype != grub_scsi_devtype_cdrom) { + grub_free (scsi); return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "unknown SCSI device"); } @@ -287,6 +290,7 @@ grub_scsi_open (const char *name, grub_disk_t disk) err = grub_scsi_read_capacity (scsi); if (err) { + grub_free (scsi); grub_dprintf ("scsi", "READ CAPACITY failed\n"); return grub_errno; } @@ -303,6 +307,8 @@ grub_scsi_open (const char *name, grub_disk_t disk) } } + grub_free (scsi); + return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "not a SCSI disk"); } diff --git a/kern/disk.c b/kern/disk.c index 4ee03e0..8a92989 100644 --- a/kern/disk.c +++ b/kern/disk.c @@ -158,10 +158,13 @@ grub_disk_cache_store (unsigned long dev_id, unsigned long disk_id, unsigned index; struct grub_disk_cache *cache; - grub_disk_cache_invalidate (dev_id, disk_id, sector); - index = grub_disk_cache_get_index (dev_id, disk_id, sector); cache = grub_disk_cache_table + index; + + cache->lock = 1; + grub_free (cache->data); + cache->data = 0; + cache->lock = 0; cache->data = grub_malloc (GRUB_DISK_SECTOR_SIZE << GRUB_DISK_CACHE_BITS); if (! cache->data) --------------000501050006070702050607--