From 37306a004239d45dd8d5c6bc8ccf4a567d28dd4a Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Sun, 21 Mar 2021 18:33:17 +0200 Subject: [PATCH] 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 --- wpa_supplicant/pasn_supplicant.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/wpa_supplicant/pasn_supplicant.c b/wpa_supplicant/pasn_supplicant.c index cacba7c26..53ba21c5a 100644 --- a/wpa_supplicant/pasn_supplicant.c +++ b/wpa_supplicant/pasn_supplicant.c @@ -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) { 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; } - wpabuf_free(awork->comeback); - os_free(awork); + wpas_pasn_free_auth_work(awork); 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; return; fail: - wpabuf_free(awork->comeback); - awork->comeback = NULL; - os_free(awork); + wpas_pasn_free_auth_work(awork); work->ctx = NULL; 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) { awork->comeback = wpabuf_alloc_copy(comeback, comeback_len); if (!awork->comeback) { - os_free(awork); + wpas_pasn_free_auth_work(awork); return -1; } } if (radio_add_work(wpa_s, bss->freq, "pasn-start-auth", 1, wpas_pasn_auth_start_cb, awork) < 0) { - wpabuf_free(awork->comeback); - os_free(awork); + wpas_pasn_free_auth_work(awork); return -1; }