wpa_supplicant: Free config only if it was allocated in same call
(cherry-picked from 9c5fe742a25d2361b49051aef5b1ed0083494b6c)
If option -I:config points to a non-existing file, the the previously
allocated config must not be freed. Avoid use of freed memory in such an
error case by skipping the incorrect freeing operation.
Bug: 72740284
Test: Manual
Change-Id: I11f36fb5f77b3fca033268c8d16656679c356054
Signed-off-by: Dmitry Shmidt <dimitrysh@google.com>
diff --git a/wpa_supplicant/config_file.c b/wpa_supplicant/config_file.c
index 6b7abe2..0d70850 100644
--- a/wpa_supplicant/config_file.c
+++ b/wpa_supplicant/config_file.c
@@ -397,7 +397,8 @@
if (f == NULL) {
wpa_printf(MSG_ERROR, "Failed to open config file '%s', "
"error: %s", name, strerror(errno));
- os_free(config);
+ if (config != cfgp)
+ os_free(config);
return NULL;
}