Free old eap_user_file data on configuration change
authorJouni Malinen <jouni@qca.qualcomm.com>
Thu, 29 Jan 2015 22:54:40 +0000 (00:54 +0200)
committerJouni Malinen <j@w1.fi>
Thu, 29 Jan 2015 22:54:40 +0000 (00:54 +0200)
This fixes a memory leak if hostapd eap_user_file parameter is modified.

Signed-off-by: Jouni Malinen <jouni@qca.qualcomm.com>
hostapd/config_file.c

index 7cbb46b..e3cad7c 100644 (file)
@@ -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 */