From 2f444dc7f645cd9a82aa74005a0da76dea09eb6e Mon Sep 17 00:00:00 2001 From: Otavio Pontes Date: Mon, 11 Jun 2018 21:48:35 +0000 Subject: [PATCH] fullfile: Fix double free String that is reused later shoudn't be freed. Fix double free reported on issue #480 --- src/fullfile.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/fullfile.c b/src/fullfile.c index 2bcfb5e7..aa26d703 100644 --- a/src/fullfile.c +++ b/src/fullfile.c @@ -46,21 +46,24 @@ static struct list *download_loop(struct list *files, bool free_list) /* Mix content is local, so don't queue files up for curl downloads */ if (file->is_mix) { - char *filename; char *url; + + if (file->staging) { + free_string(&file->staging); + } + string_or_die(&url, "%s/%i/files/%s.tar", MIX_STATE_DIR, file->last_change, file->hash); - string_or_die(&filename, "%s/download/.%s.tar", state_dir, file->hash); - file->staging = filename; - ret = link(url, filename); + string_or_die(&file->staging, "%s/download/.%s.tar", state_dir, file->hash); + + ret = link(url, file->staging); /* Try doing a regular rename if hardlink fails */ if (ret) { - if (rename(url, filename) != 0) { - fprintf(stderr, "Failed to copy local mix file: %s\n", filename); + if (rename(url, file->staging) != 0) { + fprintf(stderr, "Failed to copy local mix file: %s\n", file->staging); continue; } } untar_full_download(file); - free_string(&filename); free_string(&url); continue; }