hostapd: Fix early init failure path

eloop deinit calls could trigger segmentation fault if the early error
path is hit before eloop_init() gets called.

Signed-off-by: Jouni Malinen <j@w1.fi>
This commit is contained in:
Jouni Malinen 2016-06-13 00:36:18 +03:00
parent 976dfb3237
commit cc27c8e680
2 changed files with 8 additions and 4 deletions

View file

@ -339,6 +339,7 @@ static int hostapd_global_init(struct hapd_interfaces *interfaces,
wpa_printf(MSG_ERROR, "Failed to initialize event loop");
return -1;
}
interfaces->eloop_initialized = 1;
random_init(entropy_file);
@ -366,7 +367,7 @@ static int hostapd_global_init(struct hapd_interfaces *interfaces,
}
static void hostapd_global_deinit(const char *pid_file)
static void hostapd_global_deinit(const char *pid_file, int eloop_initialized)
{
int i;
@ -384,7 +385,8 @@ static void hostapd_global_deinit(const char *pid_file)
random_deinit();
eloop_destroy();
if (eloop_initialized)
eloop_destroy();
#ifndef CONFIG_NATIVE_WINDOWS
closelog();
@ -816,8 +818,9 @@ int main(int argc, char *argv[])
}
os_free(interfaces.iface);
eloop_cancel_timeout(hostapd_periodic, &interfaces, NULL);
hostapd_global_deinit(pid_file);
if (interfaces.eloop_initialized)
eloop_cancel_timeout(hostapd_periodic, &interfaces, NULL);
hostapd_global_deinit(pid_file, interfaces.eloop_initialized);
os_free(pid_file);
if (log_file)

View file

@ -53,6 +53,7 @@ struct hapd_interfaces {
#ifndef CONFIG_NO_VLAN
struct dynamic_iface *vlan_priv;
#endif /* CONFIG_NO_VLAN */
int eloop_initialized;
};
enum hostapd_chan_status {