summaryrefslogtreecommitdiffstats
path: root/src/import/curl-util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/import/curl-util.c')
-rw-r--r--src/import/curl-util.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/import/curl-util.c b/src/import/curl-util.c
index 24011860f7..05b17c3c78 100644
--- a/src/import/curl-util.c
+++ b/src/import/curl-util.c
@@ -222,24 +222,31 @@ CurlGlue *curl_glue_unref(CurlGlue *g) {
int curl_glue_new(CurlGlue **glue, sd_event *event) {
_cleanup_(curl_glue_unrefp) CurlGlue *g = NULL;
+ _cleanup_(curl_multi_cleanupp) CURL *c = NULL;
+ _cleanup_(sd_event_unrefp) sd_event *e = NULL;
int r;
- g = new0(CurlGlue, 1);
- if (!g)
- return -ENOMEM;
-
if (event)
- g->event = sd_event_ref(event);
+ e = sd_event_ref(event);
else {
- r = sd_event_default(&g->event);
+ r = sd_event_default(&e);
if (r < 0)
return r;
}
- g->curl = curl_multi_init();
- if (!g->curl)
+ c = curl_multi_init();
+ if (!c)
+ return -ENOMEM;
+
+ g = new(CurlGlue, 1);
+ if (!g)
return -ENOMEM;
+ *g = (CurlGlue) {
+ .event = TAKE_PTR(e),
+ .curl = TAKE_PTR(c),
+ };
+
if (curl_multi_setopt(g->curl, CURLMOPT_SOCKETDATA, g) != CURLM_OK)
return -EINVAL;