From 286e563fbea872e6759cb0c4845bff4525cb2e3a Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Fri, 27 Feb 2026 21:13:45 +0100 Subject: [PATCH] fix: fix redundant error reporting in http download We were sequentially checking for errors from 'curl_easy_perform', 'ftell', and 'fclose'. Each time overwriting the last one, resulting in a leak. This commit ensures that 'err' is only set if it is currently NULL, preserving the first and most specific error encountered. --- src/tools/http_download.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/tools/http_download.c b/src/tools/http_download.c index 62ce8aa3..4f5e3b71 100644 --- a/src/tools/http_download.c +++ b/src/tools/http_download.c @@ -177,7 +177,7 @@ http_file_get(void* userdata) err = strdup(curl_easy_strerror(res)); } - if (ftell(outfh) == 0) { + if (!err && ftell(outfh) == 0) { err = strdup("Output file is empty."); } @@ -185,7 +185,9 @@ http_file_get(void* userdata) curl_global_cleanup(); if (fclose(outfh) == EOF) { - err = strdup(g_strerror(errno)); + if (!err) { + err = strdup(g_strerror(errno)); + } } pthread_mutex_lock(&lock); @@ -211,7 +213,9 @@ http_file_get(void* userdata) win_mark_received(download->window, download->id); if (download->return_bytes_received) { ret = malloc(sizeof(*ret)); - *ret = download->bytes_received; + if (ret) { + *ret = download->bytes_received; + } } } }