PASN: Use a helper function to free radio work data

This is safer in avoiding memory leaks now that there is a dynamically
allocated member within the data struct.

Signed-off-by: Jouni Malinen <j@w1.fi>
This commit is contained in:
Jouni Malinen 2021-03-21 18:33:17 +02:00
parent 349e9eafbb
commit 37306a0042

View file

@ -37,6 +37,14 @@ struct wpa_pasn_auth_work {
}; };
static void wpas_pasn_free_auth_work(struct wpa_pasn_auth_work *awork)
{
wpabuf_free(awork->comeback);
awork->comeback = NULL;
os_free(awork);
}
static void wpas_pasn_auth_work_timeout(void *eloop_ctx, void *timeout_ctx) static void wpas_pasn_auth_work_timeout(void *eloop_ctx, void *timeout_ctx)
{ {
struct wpa_supplicant *wpa_s = eloop_ctx; struct wpa_supplicant *wpa_s = eloop_ctx;
@ -1134,8 +1142,7 @@ static void wpas_pasn_auth_start_cb(struct wpa_radio_work *work, int deinit)
wpa_s->pasn_auth_work = NULL; wpa_s->pasn_auth_work = NULL;
} }
wpabuf_free(awork->comeback); wpas_pasn_free_auth_work(awork);
os_free(awork);
return; return;
} }
@ -1176,9 +1183,7 @@ static void wpas_pasn_auth_start_cb(struct wpa_radio_work *work, int deinit)
wpa_s->pasn_auth_work = work; wpa_s->pasn_auth_work = work;
return; return;
fail: fail:
wpabuf_free(awork->comeback); wpas_pasn_free_auth_work(awork);
awork->comeback = NULL;
os_free(awork);
work->ctx = NULL; work->ctx = NULL;
radio_work_done(work); radio_work_done(work);
} }
@ -1235,15 +1240,14 @@ int wpas_pasn_auth_start(struct wpa_supplicant *wpa_s, const u8 *bssid,
if (comeback && comeback_len) { if (comeback && comeback_len) {
awork->comeback = wpabuf_alloc_copy(comeback, comeback_len); awork->comeback = wpabuf_alloc_copy(comeback, comeback_len);
if (!awork->comeback) { if (!awork->comeback) {
os_free(awork); wpas_pasn_free_auth_work(awork);
return -1; return -1;
} }
} }
if (radio_add_work(wpa_s, bss->freq, "pasn-start-auth", 1, if (radio_add_work(wpa_s, bss->freq, "pasn-start-auth", 1,
wpas_pasn_auth_start_cb, awork) < 0) { wpas_pasn_auth_start_cb, awork) < 0) {
wpabuf_free(awork->comeback); wpas_pasn_free_auth_work(awork);
os_free(awork);
return -1; return -1;
} }