From cd195197519c397d475a427baa6ee3c1553c393d Mon Sep 17 00:00:00 2001
From: Maxime Bizon <mbizon@freebox.fr>
Date: Mon, 4 Nov 2013 21:51:07 +0100
Subject: [PATCH 02/18] hostapd: fix crash when failing to setup new
 interface.

Got this crash using new "bss_config" method with an unsupported
hw_mode in config file.

Signed-hostap: Maxime Bizon <mbizon@freebox.fr>
---
 src/ap/hostapd.c |   17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/src/ap/hostapd.c b/src/ap/hostapd.c
index 614a5bf..fff769e 100644
--- a/src/ap/hostapd.c
+++ b/src/ap/hostapd.c
@@ -1840,8 +1840,21 @@ int hostapd_add_iface(struct hapd_interfaces *interfaces, char *buf)
 		}
 
 		if (new_iface) {
-			if (interfaces->driver_init(hapd_iface) ||
-			    hostapd_setup_interface(hapd_iface)) {
+			const struct wpa_driver_ops *driver;
+			void *drv_priv;
+
+			if (interfaces->driver_init(hapd_iface)) {
+				interfaces->count--;
+				goto fail;
+			}
+
+			driver = hapd_iface->bss[0]->driver;
+			drv_priv = hapd_iface->bss[0]->drv_priv;
+
+			if (hostapd_setup_interface(hapd_iface)) {
+				if (driver &&
+				    driver->hapd_deinit && drv_priv)
+					driver->hapd_deinit(drv_priv);
 				interfaces->count--;
 				goto fail;
 			}
-- 
1.7.9.5

