scan: More cleanup in scan_cancel

Add sr NULL check before accessing sr->id.  Call scan_request_free on
request structure and call the destroy callback.  Cancel the netlink
TRIGGER_SCAN command if still running and try starting the next scan
in the queue.  It'll probably still fail with EBUSY but it'll be
reattempted later.
This commit is contained in:
Andrew Zaborowski 2017-02-08 01:38:42 +01:00 committed by Denis Kenzior
parent cc6d0cf2db
commit 2756f24f0e
1 changed files with 22 additions and 2 deletions

View File

@ -388,9 +388,23 @@ bool scan_cancel(uint32_t ifindex, uint32_t id)
return false;
sr = l_queue_peek_head(sc->requests);
if (!sr)
return false;
/* If the scan has already been triggered, just zero out the callback */
if (sr->id == id && sr->triggered) {
/* If we already sent the trigger command, cancel the scan */
if (sr->id == id && !sr->start_cmd) {
if (!sr->triggered && sc->start_cmd_id) {
l_genl_family_cancel(nl80211, sc->start_cmd_id);
sc->start_cmd_id = 0;
l_queue_pop_head(sc->requests);
start_next_scan_request(sc);
goto free;
}
/* If already triggered, just zero out the callback */
sr->callback = NULL;
if (sr->destroy) {
@ -406,6 +420,12 @@ bool scan_cancel(uint32_t ifindex, uint32_t id)
if (!sr)
return false;
free:
if (sr->destroy)
sr->destroy(sr->userdata);
scan_request_free(sr);
return true;
}