diff mbox

[4/4] hostapd: Clean up if interface setup fails

Message ID 1401271032-7690-5-git-send-email-michal.kazior@tieto.com
State Accepted
Headers show

Commit Message

Michal Kazior May 28, 2014, 9:57 a.m. UTC
If for some reason interface setup fails mid-way when setting up
multi-BSS AP it was possible to get segmentation fault because driver
was not properly cleaned up.

One possible trigger when using nl80211 driver was udev renaming an
interface created by hostapd causing, e.g. linux_set_iface_flags() to
fail.

Signed-off-by: Michal Kazior <michal.kazior@tieto.com>
---
 src/ap/hostapd.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
diff mbox

Patch

diff --git a/src/ap/hostapd.c b/src/ap/hostapd.c
index d6f937c..d5c83e5 100644
--- a/src/ap/hostapd.c
+++ b/src/ap/hostapd.c
@@ -1229,8 +1229,16 @@  int hostapd_setup_interface_complete(struct hostapd_iface *iface, int err)
 		hapd = iface->bss[j];
 		if (j)
 			os_memcpy(hapd->own_addr, prev_addr, ETH_ALEN);
-		if (hostapd_setup_bss(hapd, j == 0))
+		if (hostapd_setup_bss(hapd, j == 0)) {
+			do {
+				hapd = iface->bss[j];
+				hostapd_free_stas(hapd);
+				hostapd_flush_old_stations(hapd, WLAN_REASON_DEAUTH_LEAVING);
+				hostapd_clear_wep(hapd);
+				hostapd_free_hapd_data(hapd);
+			} while (j-- > 0);
 			goto fail;
+		}
 		if (hostapd_mac_comp_empty(hapd->conf->bssid) == 0)
 			prev_addr = hapd->own_addr;
 	}