]> git.ipfire.org Git - pakfire.git/commitdiff
repo: Avoid double-free when downloading files
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 26 Jan 2025 15:22:02 +0000 (15:22 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 26 Jan 2025 15:22:02 +0000 (15:22 +0000)
We pass control over f to xfer which will close it, so we cannot call
fclose() ourselves any more.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/repo.c

index 5403b6af6fcd0c3b199725d5aebdab091600fd51..3a6b4b602b28acb6292fdc20fad81bda5d5afe8d 100644 (file)
@@ -1270,7 +1270,7 @@ static int pakfire_repo_download(struct pakfire_repo* repo, const char* url,
        // Allocate a temporary file name
        f = pakfire_mktemp(path, 0);
        if (!f) {
-               r = 1;
+               r = -errno;
                goto ERROR;
        }
 
@@ -1284,6 +1284,9 @@ static int pakfire_repo_download(struct pakfire_repo* repo, const char* url,
        if (r)
                goto ERROR;
 
+       // Reset f since its control has been passed to xfer
+       f = NULL;
+
        // Run the download
        r = pakfire_xfer_run(xfer, 0);
        if (r)