autoupdater: uclient: add error handling in connection setup
Avoids a segfault when the connection fails early.
This commit is contained in:
parent
d14cedea14
commit
fc194bc7c8
|
@ -162,12 +162,18 @@ int get_url(const char *url, void (*read_cb)(struct uclient *cl), void *cb_data,
|
||||||
|
|
||||||
struct uclient *cl = uclient_new(url, NULL, &cb);
|
struct uclient *cl = uclient_new(url, NULL, &cb);
|
||||||
cl->priv = &d;
|
cl->priv = &d;
|
||||||
uclient_set_timeout(cl, TIMEOUT_MSEC);
|
if (uclient_set_timeout(cl, TIMEOUT_MSEC))
|
||||||
uclient_connect(cl);
|
goto err;
|
||||||
uclient_http_set_request_type(cl, "GET");
|
if (uclient_connect(cl))
|
||||||
uclient_http_reset_headers(cl);
|
goto err;
|
||||||
uclient_http_set_header(cl, "User-Agent", user_agent);
|
if (uclient_http_set_request_type(cl, "GET"))
|
||||||
uclient_request(cl);
|
goto err;
|
||||||
|
if (uclient_http_reset_headers(cl))
|
||||||
|
goto err;
|
||||||
|
if (uclient_http_set_header(cl, "User-Agent", user_agent))
|
||||||
|
goto err;
|
||||||
|
if (uclient_request(cl))
|
||||||
|
goto err;
|
||||||
uloop_run();
|
uloop_run();
|
||||||
uclient_free(cl);
|
uclient_free(cl);
|
||||||
|
|
||||||
|
@ -175,4 +181,8 @@ int get_url(const char *url, void (*read_cb)(struct uclient *cl), void *cb_data,
|
||||||
return UCLIENT_ERROR_SIZE_MISMATCH;
|
return UCLIENT_ERROR_SIZE_MISMATCH;
|
||||||
|
|
||||||
return d.err_code;
|
return d.err_code;
|
||||||
|
|
||||||
|
err:
|
||||||
|
uclient_free(cl);
|
||||||
|
return UCLIENT_ERROR_CONNECT;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue