From: phcoder <phcoder@gmail.com>
To: The development of GRUB 2 <grub-devel@gnu.org>
Subject: Re: Leak fixes
Date: Sun, 22 Mar 2009 14:09:52 +0100 [thread overview]
Message-ID: <49C638A0.3060506@gmail.com> (raw)
In-Reply-To: <49B52C12.5080105@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 560 bytes --]
Rediffed
2009-03-22 Vladimir Serbinenko <phcoder@gmail.com>
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
[-- Attachment #2: leakfixes.diff --]
[-- Type: text/x-patch, Size: 1894 bytes --]
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)
next prev parent reply other threads:[~2009-03-22 13:10 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-09 14:47 Leak fixes phcoder
2009-03-22 13:09 ` phcoder [this message]
2009-03-22 13:45 ` Robert Millan
2009-03-22 13:52 ` phcoder
2009-03-29 21:21 ` phcoder
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=49C638A0.3060506@gmail.com \
--to=phcoder@gmail.com \
--cc=grub-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.