From 4437f8fc778e6272b16ad5f120ecf3ac1ac7700c Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Fri, 30 Jan 2015 00:54:40 +0200 Subject: [PATCH] Free old eap_user_file data on configuration change This fixes a memory leak if hostapd eap_user_file parameter is modified. Signed-off-by: Jouni Malinen --- hostapd/config_file.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/hostapd/config_file.c b/hostapd/config_file.c index 7cbb46b46..e3cad7c9f 100644 --- a/hostapd/config_file.c +++ b/hostapd/config_file.c @@ -216,7 +216,7 @@ static int hostapd_config_read_eap_user(const char *fname, FILE *f; char buf[512], *pos, *start, *pos2; int line = 0, ret = 0, num_methods; - struct hostapd_eap_user *user = NULL, *tail = NULL; + struct hostapd_eap_user *user = NULL, *tail = NULL, *new_user = NULL; if (!fname) return 0; @@ -494,7 +494,7 @@ static int hostapd_config_read_eap_user(const char *fname, done: if (tail == NULL) { - tail = conf->eap_user = user; + tail = new_user = user; } else { tail->next = user; tail = user; @@ -510,6 +510,18 @@ static int hostapd_config_read_eap_user(const char *fname, fclose(f); + if (ret == 0) { + user = conf->eap_user; + while (user) { + struct hostapd_eap_user *prev; + + prev = user; + user = user->next; + hostapd_config_free_eap_user(prev); + } + conf->eap_user = new_user; + } + return ret; } #endif /* EAP_SERVER */