Don't leak layer names

This commit is contained in:
Eric Fischer 2016-04-27 10:31:10 -07:00
parent 1e16eb9294
commit 5cfd7cf68f

View File

@ -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;
}