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.
This commit is contained in:
@@ -177,7 +177,7 @@ http_file_get(void* userdata)
|
|||||||
err = strdup(curl_easy_strerror(res));
|
err = strdup(curl_easy_strerror(res));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ftell(outfh) == 0) {
|
if (!err && ftell(outfh) == 0) {
|
||||||
err = strdup("Output file is empty.");
|
err = strdup("Output file is empty.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -185,7 +185,9 @@ http_file_get(void* userdata)
|
|||||||
curl_global_cleanup();
|
curl_global_cleanup();
|
||||||
|
|
||||||
if (fclose(outfh) == EOF) {
|
if (fclose(outfh) == EOF) {
|
||||||
err = strdup(g_strerror(errno));
|
if (!err) {
|
||||||
|
err = strdup(g_strerror(errno));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pthread_mutex_lock(&lock);
|
pthread_mutex_lock(&lock);
|
||||||
@@ -211,7 +213,9 @@ http_file_get(void* userdata)
|
|||||||
win_mark_received(download->window, download->id);
|
win_mark_received(download->window, download->id);
|
||||||
if (download->return_bytes_received) {
|
if (download->return_bytes_received) {
|
||||||
ret = malloc(sizeof(*ret));
|
ret = malloc(sizeof(*ret));
|
||||||
*ret = download->bytes_received;
|
if (ret) {
|
||||||
|
*ret = download->bytes_received;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user