From: Michael Tremer Date: Sun, 13 Oct 2024 10:18:17 +0000 (+0000) Subject: xfer: Keep a reference to ourselves X-Git-Tag: 0.9.30~1048 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e0d803e9a9c15c32be3c202afe76feecfd7d52d8;p=pakfire.git xfer: Keep a reference to ourselves This is necessary so that the handle won't be cleaned up when the last reference to the xfer is gone. It should be good enough to add the xfer to the HTTP client and then wait for everything to complete. Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/xfer.c b/src/libpakfire/xfer.c index beb12f307..c086b9543 100644 --- a/src/libpakfire/xfer.c +++ b/src/libpakfire/xfer.c @@ -307,7 +307,7 @@ static int pakfire_xfer_setup(struct pakfire_xfer* xfer) { curl_easy_setopt(xfer->handle, CURLOPT_ACCEPT_ENCODING, ""); // Reference back to this xfer - curl_easy_setopt(xfer->handle, CURLOPT_PRIVATE, xfer); + curl_easy_setopt(xfer->handle, CURLOPT_PRIVATE, pakfire_xfer_ref(xfer)); // Follow any redirects curl_easy_setopt(xfer->handle, CURLOPT_FOLLOWLOCATION, 1); @@ -1130,6 +1130,7 @@ static int pakfire_xfer_save(struct pakfire_xfer* xfer) { } pakfire_xfer_error_code_t pakfire_xfer_done(struct pakfire_xfer* xfer, int code) { + struct pakfire_xfer* private = NULL; CURL* h = xfer->handle; int r; const char* scheme = NULL; @@ -1142,6 +1143,29 @@ pakfire_xfer_error_code_t pakfire_xfer_done(struct pakfire_xfer* xfer, int code) curl_off_t upload_size = 0; curl_off_t upload_speed = 0; + // Fetch the private pointer to this xfer + r = curl_easy_getinfo(h, CURLINFO_PRIVATE, &private); + if (r) { + CTX_ERROR(xfer->ctx, + "Could not fetch the private pointer: %s\n", curl_easy_strerror(r)); + goto ERROR; + } + + // Check if the private pointer was set + if (!private) { + CTX_ERROR(xfer->ctx, "Private pointer not set\n"); + r = -EINVAL; + goto ERROR; + } + + // Reset the private pointer + r = curl_easy_setopt(h, CURLOPT_PRIVATE, NULL); + if (r) { + CTX_ERROR(xfer->ctx, + "Could not reset the private pointer: %s\n", curl_easy_strerror(r)); + goto ERROR; + } + // Finish progress r = pakfire_progress_finish(xfer->progress); if (r) @@ -1283,6 +1307,8 @@ ERROR: // Remove the handle if (xfer->client) pakfire_httpclient_remove_xfer(xfer->client, xfer); + if (private) + pakfire_xfer_unref(private); return r; }