From: Marios Paouris Date: Mon, 23 Sep 2024 06:12:27 +0000 (+0300) Subject: Fix memory leaks. openconnect__win32_strerror returns a malloc\'ed string X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=136ffea0bbd2545a1392510daa58d6acdee6bdba;p=users%2Fdwmw2%2Fopenconnect.git Fix memory leaks. openconnect__win32_strerror returns a malloc\'ed string Signed-off-by: Marios Paouris --- diff --git a/tests/list-taps.c b/tests/list-taps.c index 8482896e..c63ab07d 100644 --- a/tests/list-taps.c +++ b/tests/list-taps.c @@ -31,7 +31,7 @@ struct openconnect_info { /* don't link linkopenconnect in this test, just for this function * it won't get loaded under wine when cross compiling anyway */ -#define openconnect__win32_strerror(err) "(Actual error text not present in tests)" +#define openconnect__win32_strerror(err) (strdup("(Actual error text not present in tests)")) #define OPEN_TUN_SOFTFAIL 0 #define OPEN_TUN_HARDFAIL -1 diff --git a/tests/wintun-names.c b/tests/wintun-names.c index 22430de4..ab9a073b 100644 --- a/tests/wintun-names.c +++ b/tests/wintun-names.c @@ -47,7 +47,7 @@ struct openconnect_info { /* don't link linkopenconnect in this test, just for this function * it won't get loaded under wine when cross compiling anyway */ -#define openconnect__win32_strerror(err) "(Actual error text not present in tests)" +#define openconnect__win32_strerror(err) (strdup("(Actual error text not present in tests)")) #define OPEN_TUN_SOFTFAIL 0 #define OPEN_TUN_HARDFAIL -1 diff --git a/tun-win32.c b/tun-win32.c index 0a1d1436..c09756b2 100644 --- a/tun-win32.c +++ b/tun-win32.c @@ -164,9 +164,11 @@ static struct oc_adapter_info * get_adapter_list(struct openconnect_info *vpninf status = RegOpenKeyExA(HKEY_LOCAL_MACHINE, keyname, 0, KEY_QUERY_VALUE, &hkey); if (status) { + char *errstr = openconnect__win32_strerror(status); vpn_progress(vpninfo, PRG_TRACE, _("Cannot open registry key %s: %s (%ld)\n"), - keyname, openconnect__win32_strerror(status), status); + keyname, errstr, status); + free(errstr); continue; } @@ -185,9 +187,11 @@ static struct oc_adapter_info * get_adapter_list(struct openconnect_info *vpninf keyname, "ComponentId", type); } else { + char *errstr = openconnect__win32_strerror(status); vpn_progress(vpninfo, PRG_TRACE, _("Cannot read registry key %s\\%s or is not string: %s (%ld)\n"), - keyname, "ComponentId", openconnect__win32_strerror(status), status); + keyname, "ComponentId", errstr, status); + free(errstr); } RegCloseKey(hkey); continue; @@ -248,9 +252,11 @@ static struct oc_adapter_info * get_adapter_list(struct openconnect_info *vpninf keyname, "Name", type); } else { + char *errstr = openconnect__win32_strerror(status); vpn_progress(vpninfo, PRG_INFO, _("Cannot read registry key %s\\%s: %s (%ld)\n"), - keyname, "Name", openconnect__win32_strerror(status), status); + keyname, "Name", errstr, status); + free(errstr); } continue; } @@ -374,6 +380,7 @@ static int check_address_conflicts(struct openconnect_info *vpninfo) if (LastError != ERROR_SUCCESS) { char *errstr = openconnect__win32_strerror(LastError); vpn_progress(vpninfo, PRG_ERR, _("GetAdaptersAddresses() failed: %s\n"), errstr); + free(errstr); ret = -EIO; goto out; } @@ -425,6 +432,7 @@ static int check_address_conflicts(struct openconnect_info *vpninfo) if (LastError != ERROR_SUCCESS) { char *errstr = openconnect__win32_strerror(LastError); vpn_progress(vpninfo, PRG_ERR, _("GetUnicastIpAddressTable() failed: %s\n"), errstr); + free(errstr); ret = -EIO; goto out; } @@ -446,6 +454,7 @@ static int check_address_conflicts(struct openconnect_info *vpninfo) if (LastError != NO_ERROR) { char *errstr = openconnect__win32_strerror(LastError); vpn_progress(vpninfo, PRG_ERR, _("DeleteUnicastIpAddressEntry() failed: %s\n"), errstr); + free(errstr); ret = -EIO; goto out; }