Skip to content

Commit 9249ca2

Browse files
rscharfegitster
authored andcommitted
khash: factor out kh_release_*
Add a function for releasing the khash-internal allocations, but not the khash structure itself. It can be used with on-stack khash structs. Signed-off-by: Rene Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 22a1646 commit 9249ca2

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

khash.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,16 @@ static const double __ac_HASH_UPPER = 0.77;
8282
SCOPE kh_##name##_t *kh_init_##name(void) { \
8383
return (kh_##name##_t*)xcalloc(1, sizeof(kh_##name##_t)); \
8484
} \
85+
SCOPE void kh_release_##name(kh_##name##_t *h) \
86+
{ \
87+
free(h->flags); \
88+
free((void *)h->keys); \
89+
free((void *)h->vals); \
90+
} \
8591
SCOPE void kh_destroy_##name(kh_##name##_t *h) \
8692
{ \
8793
if (h) { \
88-
free((void *)h->keys); free(h->flags); \
89-
free((void *)h->vals); \
94+
kh_release_##name(h); \
9095
free(h); \
9196
} \
9297
} \

0 commit comments

Comments
 (0)