]> git.kaiwu.me - klib.git/commitdiff
fix the leak that happens if krealloc fails
authorPatrick Reynolds <patrick.reynolds@github.com>
Sun, 9 Feb 2014 08:24:08 +0000 (02:24 -0600)
committerPatrick Reynolds <patrick.reynolds@github.com>
Sun, 9 Feb 2014 08:24:08 +0000 (02:24 -0600)
khash.h

diff --git a/khash.h b/khash.h
index 2d910dec274e191eee39ac575727ba4cc1c53292..20f16b94b1f0badd691a58b4221b267b56e2f10b 100644 (file)
--- a/khash.h
+++ b/khash.h
@@ -245,11 +245,11 @@ static const double __ac_HASH_UPPER = 0.77;
                                memset(new_flags, 0xaa, __ac_fsize(new_n_buckets) * sizeof(khint32_t)); \
                                if (h->n_buckets < new_n_buckets) {     /* expand */            \
                                        khkey_t *new_keys = (khkey_t*)krealloc((void *)h->keys, new_n_buckets * sizeof(khkey_t)); \
-                                       if (!new_keys) return -1;                                                       \
+                                       if (!new_keys) { kfree(new_flags); return -1; }         \
                                        h->keys = new_keys;                                                                     \
                                        if (kh_is_map) {                                                                        \
                                                khval_t *new_vals = (khval_t*)krealloc((void *)h->vals, new_n_buckets * sizeof(khval_t)); \
-                                               if (!new_vals) return -1;                                               \
+                                               if (!new_vals) { kfree(new_flags); return -1; } \
                                                h->vals = new_vals;                                                             \
                                        }                                                                                                       \
                                } /* otherwise shrink */                                                                \