Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2012-05-04 22:06:12 +0400
committerRussell Belfer <rb@github.com>2012-05-04 22:06:12 +0400
commitb709e95146b9d56e2c009915ccea7a86c77d4202 (patch)
treec9257b8278c8d1e28b0cfe5969317ef0ed63c315 /src/strmap.h
parentf917481ee84cbba481c1854cccdedb2d98377d43 (diff)
Fix memory leaks and use after free
Diffstat (limited to 'src/strmap.h')
-rw-r--r--src/strmap.h28
1 files changed, 19 insertions, 9 deletions
diff --git a/src/strmap.h b/src/strmap.h
index 55fbd7c6e..da5ca0dba 100644
--- a/src/strmap.h
+++ b/src/strmap.h
@@ -36,18 +36,28 @@ typedef khash_t(str) git_strmap;
#define git_strmap_set_value_at(h, idx, v) kh_val(h, idx) = v
#define git_strmap_delete_at(h, idx) kh_del(str, h, idx)
-#define git_strmap_insert(h, key, val, err) do { \
- khiter_t __pos = kh_put(str, h, key, &err); \
- if (err >= 0) kh_val(h, __pos) = val; \
- } while (0)
-
-#define git_strmap_insert2(h, key, val, old, err) do { \
- khiter_t __pos = kh_put(str, h, key, &err); \
- if (err >= 0) { \
- old = (err == 0) ? kh_val(h, __pos) : NULL; \
+#define git_strmap_insert(h, key, val, rval) do { \
+ khiter_t __pos = kh_put(str, h, key, &rval); \
+ if (rval >= 0) { \
+ if (rval == 0) kh_key(h, __pos) = key; \
kh_val(h, __pos) = val; \
} } while (0)
+#define git_strmap_insert2(h, key, val, oldv, rval) do { \
+ khiter_t __pos = kh_put(str, h, key, &rval); \
+ if (rval >= 0) { \
+ if (rval == 0) { \
+ oldv = kh_val(h, __pos); \
+ kh_key(h, __pos) = key; \
+ } else { oldv = NULL; } \
+ kh_val(h, __pos) = val; \
+ } } while (0)
+
+#define git_strmap_delete(h, key) do { \
+ khiter_t __pos = git_strmap_lookup_index(h, key); \
+ if (git_strmap_valid_index(h, __pos)) \
+ git_strmap_delete_at(h, __pos); } while (0)
+
#define git_strmap_foreach kh_foreach
#define git_strmap_foreach_value kh_foreach_value