In case we have a mirror failure, unlink_on_fail would remain set, causing an interrupt in a successive download attempt to be wrongly unlinked. This also fixes a memory leak in the url member, as we would allocate over the previous, unfreed URL. Signed-off-by: Dave Reisner <dreisner@archlinux.org> --- lib/libalpm/sync.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c index 69d27af..feab302 100644 --- a/lib/libalpm/sync.c +++ b/lib/libalpm/sync.c @@ -864,6 +864,9 @@ static int download_single_file(alpm_handle_t *handle, struct dload_payload *pay { const alpm_list_t *server; + payload->handle = handle; + payload->allow_resume = 1; + for(server = payload->servers; server; server = server->next) { const char *server_url = server->data; size_t len; @@ -872,12 +875,15 @@ static int download_single_file(alpm_handle_t *handle, struct dload_payload *pay len = strlen(server_url) + strlen(payload->remote_name) + 2; MALLOC(payload->fileurl, len, RET_ERR(handle, ALPM_ERR_MEMORY, -1)); snprintf(payload->fileurl, len, "%s/%s", server_url, payload->remote_name); - payload->handle = handle; - payload->allow_resume = 1; if(_alpm_download(payload, cachedir, NULL) != -1) { return 0; } + + /* we failed the download, clean out the URL and any bits that might be + * set in _alpm_download */ + payload->unlink_on_fail = 0; + free(payload->fileurl); } return -1; -- 1.7.9.4