network: increment reference counters of Link and Request before processing requests

To prevent the request or link is freed while processing requests.
This commit is contained in:
Yu Watanabe
2022-02-28 11:21:24 +09:00
parent eb93dc9bde
commit 4c8b81caa5

View File

@@ -418,6 +418,9 @@ int manager_process_requests(sd_event_source *s, void *userdata) {
Request *req;
ORDERED_SET_FOREACH(req, manager->request_queue) {
_unused_ _cleanup_(request_unrefp) Request *ref = request_ref(req);
_cleanup_(link_unrefp) Link *link = link_ref(req->link);
switch (req->type) {
case REQUEST_TYPE_ACTIVATE_LINK:
r = link_process_activation(req, req->link, req->userdata);
@@ -501,10 +504,15 @@ int manager_process_requests(sd_event_source *s, void *userdata) {
processed = true;
request_detach(manager, req);
if (r < 0 && req->link)
link_enter_failed(req->link);
if (r < 0 && link) {
link_enter_failed(link);
/* link_enter_failed() may remove multiple requests,
* hence we need to exit from the loop. */
break;
}
}
/* When at least one request is processed, then another request may be ready now. */
if (!processed)
break;
}