Fix more (small) memory leaks

This commit is contained in:
Eric Fischer
2014-10-01 10:33:22 -07:00
parent 7df269219c
commit b292b66a7c
4 changed files with 17 additions and 1 deletions
+13 -1
View File
@@ -84,8 +84,12 @@ struct pool_val *pool_long_long(struct pool *p, long long *s, int type) {
return pool1(p, (char *) s, type, llcmp);
}
void pool_free(struct pool *p) {
void pool_free1(struct pool *p, void (*func)(void *)) {
while (p->head != NULL) {
if (func != NULL) {
func(p->head->s);
}
struct pool_val *next = p->head->next;
free(p->head);
p->head = next;
@@ -96,6 +100,14 @@ void pool_free(struct pool *p) {
p->vals = NULL;
}
void pool_free(struct pool *p) {
pool_free1(p, NULL);
}
void pool_free_strings(struct pool *p) {
pool_free1(p, free);
}
void pool_init(struct pool *p, int n) {
p->n = n;
p->vals = NULL;