From 5cfd7cf68f0550bca32f4d1c123632db92657f63 Mon Sep 17 00:00:00 2001 From: Eric Fischer Date: Wed, 27 Apr 2016 10:31:10 -0700 Subject: [PATCH] Don't leak layer names --- geojson.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/geojson.c b/geojson.c index f9124d2..e5c7afa 100644 --- a/geojson.c +++ b/geojson.c @@ -79,6 +79,22 @@ struct source { struct source *next; }; +struct tofree { + void *p; + struct tofree *next; +} *tofree = NULL; + +void mustfree(void *p) { + struct tofree *f = malloc(sizeof(struct tofree)); + if (f == NULL) { + perror("malloc"); + exit(EXIT_FAILURE); + } + f->p = p; + f->next = tofree; + tofree = f; +} + int CPUS; int TEMP_FILES; long long MAX_FILES; @@ -2580,6 +2596,8 @@ int main(int argc, char **argv) { perror("Out of memory"); exit(EXIT_FAILURE); } + mustfree(src->layer); + mustfree(src->file); src->layer[cp - optarg] = '\0'; src->next = sources; sources = src; @@ -2846,5 +2864,12 @@ int main(int argc, char **argv) { pool_free(&exclude); pool_free(&include); + struct tofree *tf, *next; + for (tf = tofree; tf != NULL; tf = next) { + next = tf->next; + free(tf->p); + free(tf); + } + return ret; }