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

View File

@ -526,6 +526,8 @@ next_feature:
tile2latlon(file_bbox[2], file_bbox[3], 32, &minlat, &maxlon);
mbtiles_write_metadata(outdb, fname, layername, minzoom, maxzoom, minlat, minlon, maxlat, maxlon, midlat, midlon, &file_keys);
pool_free_strings(&file_keys);
}
int main(int argc, char **argv) {

View File

@ -202,6 +202,7 @@ void mbtiles_write_metadata(sqlite3 *outdb, char *fname, char *layername, int mi
exit(EXIT_FAILURE);
}
sqlite3_free(sql);
free(buf);
}
void mbtiles_close(sqlite3 *outdb, char **argv) {

14
pool.c
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;

1
pool.h
View File

@ -21,5 +21,6 @@ struct pool {
struct pool_val *pool(struct pool *p, char *s, int type);
struct pool_val *pool_long_long(struct pool *p, long long *val, int type);
void pool_free(struct pool *p);
void pool_free_strings(struct pool *p);
void pool_init(struct pool *p, int n);
int is_pooled(struct pool *p, char *s, int type);