[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: another hash cleanup
From: |
Eric Blake |
Subject: |
Re: another hash cleanup |
Date: |
Thu, 18 Jun 2009 21:29:15 +0000 (UTC) |
User-agent: |
Loom/3.14 (http://gmane.org/) |
Jim Meyering <jim <at> meyering.net> writes:
> > Aargh. Ten minutes after I push, I finally see my memory leak.
> >
> > Obviously, new_table needs to be freed before returning true.
>
> Hah! I should have looked at more than the patch.
>
> Is that code path already exercised by test-hash.c?
> If so, I would have seen it eventually, via valgrind.
Yes, for example, look at op 6 in the random hash ops section (although can you
truly trust rand() to be predictable across systems?). A valgrind run would
indeed catch it (but that's too mechanical - it's more fun to find memory leaks
by code inspection ;)
Here's what I'll push:
From: Eric Blake <address@hidden>
Date: Thu, 18 Jun 2009 15:24:38 -0600
Subject: [PATCH] hash: fix memory leak in last patch
* lib/hash.c (hash_rehash): Avoid memory leak.
Signed-off-by: Eric Blake <address@hidden>
---
ChangeLog | 3 +++
lib/hash.c | 5 ++++-
2 files changed, 7 insertions(+), 1 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index e7698b7..36027fa 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
2009-06-18 Eric Blake <address@hidden>
+ hash: fix memory leak in last patch
+ * lib/hash.c (hash_rehash): Avoid memory leak.
+
hash: avoid no-op rehashing
* lib/hash.c (hash_rehash): Recognize useless rehash attempts.
diff --git a/lib/hash.c b/lib/hash.c
index f2123b4..88ae32c 100644
--- a/lib/hash.c
+++ b/lib/hash.c
@@ -863,7 +863,10 @@ hash_rehash (Hash_table *table, size_t candidate)
if (new_table == NULL)
return false;
if (new_table->n_buckets == table->n_buckets)
- return true;
+ {
+ free (new_table);
+ return true;
+ }
/* Merely reuse the extra old space into the new table. */
#if USE_OBSTACK
--
1.6.3.2
- hash and bitrotate (was: hash resizing bug), (continued)
- Re: hash resizing bug, Jim Meyering, 2009/06/18
- Re: hash resizing bug, Ben Pfaff, 2009/06/18
- another hash cleanup (was: hash resizing bug), Eric Blake, 2009/06/18
- Re: another hash cleanup, Jim Meyering, 2009/06/18
- Re: another hash cleanup, Eric Blake, 2009/06/18
- Re: another hash cleanup, Jim Meyering, 2009/06/18
- Re: another hash cleanup,
Eric Blake <=
- Re: another hash cleanup, Jim Meyering, 2009/06/19
- Re: another hash cleanup, Eric Blake, 2009/06/19
- Re: another hash cleanup, Jim Meyering, 2009/06/19
- Re: another hash cleanup, Eric Blake, 2009/06/19
- Re: another hash cleanup, Jim Meyering, 2009/06/19
- Re: another hash cleanup, Eric Blake, 2009/06/19
- Re: another hash cleanup, Jim Meyering, 2009/06/19
- Re: another hash cleanup, Eric Blake, 2009/06/19
- Re: another hash cleanup, Jim Meyering, 2009/06/19
- Re: another hash cleanup, Jim Meyering, 2009/06/19