diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2018-11-23 19:52:35 +0100 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2018-11-23 19:53:18 +0100 |
commit | 0d94088e4e9e00f5ca9afdb8e68c94558fe23268 (patch) | |
tree | 26f8388c8cb35e437a785d093c360f54509dc57f /src/import/curl-util.c | |
parent | import: use _cleanup_ attribute for CURL object (diff) | |
download | systemd-0d94088e4e9e00f5ca9afdb8e68c94558fe23268.tar.xz systemd-0d94088e4e9e00f5ca9afdb8e68c94558fe23268.zip |
import: use structured initializers
Diffstat (limited to 'src/import/curl-util.c')
-rw-r--r-- | src/import/curl-util.c | 23 |
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; |