From aaeb8d2700f1876925149ea106e3ee2594cbc60a Mon Sep 17 00:00:00 2001 From: Selva Nair Date: Mon, 30 Jan 2023 12:24:22 -0500 Subject: [PATCH] Fix memory leak in PLAP When LogonUI unloads and reloads the PLAP dll, or when the provider is released and re-created, memory allocated for config list and groups leak. - Fix by freeing config list and groups in DeleteUI We do not call this before exiting WinMain in the GUI code, as its hard to do it safely -- have to ensure all status threads have terminated. Anyway, freeing is only cosmetic in this case. Signed-off-by: Selva Nair --- openvpn_config.c | 15 +++++++++++++++ openvpn_config.h | 3 ++- plap/ui_glue.c | 2 ++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/openvpn_config.c b/openvpn_config.c index e34401b..5b000d2 100644 --- a/openvpn_config.c +++ b/openvpn_config.c @@ -466,3 +466,18 @@ BuildFileList() issue_warnings = false; } + +void +FreeConfigList(options_t *o) +{ + connection_t *next = NULL; + for (connection_t *c = o->chead; c; c = next) + { + next = c->next; + free(c); + } + free(o->groups); + o->groups = NULL; + o->num_configs = 0; + o->num_groups = 0; +} diff --git a/openvpn_config.h b/openvpn_config.h index 6c83664..d634657 100644 --- a/openvpn_config.h +++ b/openvpn_config.h @@ -24,7 +24,8 @@ #include "main.h" -void BuildFileList(); +void BuildFileList(void); bool ConfigFileOptionExist(int, const char *); +void FreeConfigList(options_t *o); #endif diff --git a/plap/ui_glue.c b/plap/ui_glue.c index f26d22b..59e466f 100644 --- a/plap/ui_glue.c +++ b/plap/ui_glue.c @@ -438,6 +438,8 @@ DeleteUI(void) dmsg(L"DeleteUI called before InitializeUI"); } DetachAllOpenVPN(); + /* at this point all status threads have terminated -- we can safely free config list */ + FreeConfigList(&o); CloseSemaphore(o.session_semaphore); WSACleanup(); memset (&o, 0, sizeof(o));