[Openvpn-devel,v2] openvpnserv: Fix memory leak when loading DLLs
Commit Message
From: Frank Lichtenheld <frank@lichtenheld.com>
Identified by cppcheck.
Change-Id: Iad3f0c36ac3795fa6a13f2d63bd00ad9c2c30d48
Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
Acked-by: Heiko Hund <heiko@openvpn.net>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1670
---
This change was reviewed on Gerrit and approved by at least one
developer. I request to merge it to master.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1670
This mail reflects revision 2 of this Change.
Acked-by according to Gerrit (reflected above):
Heiko Hund <heiko@openvpn.net>
Comments
Thanks for patch & review. I have stared a bit at the change and it
looks good, but a +2 from someone who has actually written windows
software before is better ;-)
Test compiled on MinGW.
Your patch has been applied to the master and release/2.7 branch (bugfix).
commit ae63905eb97e036756352bfc1576e5f71ffc3873 (master)
commit 494e78cc83dd73e1d59c68560a5d38cb71a22c64 (release/2.7)
Author: Frank Lichtenheld
Date: Thu May 14 11:15:06 2026 +0200
openvpnserv: Fix memory leak when loading DLLs
Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
Acked-by: Heiko Hund <heiko@openvpn.net>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1670
Message-Id: <20260514091512.17662-1-gert@greenie.muc.de>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg36913.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
--
kind regards,
Gert Doering
@@ -1071,6 +1071,7 @@
publish_fn_t RtlPublishWnfStateData;
const DWORD WNF_GPOL_SYSTEM_CHANGES_HI = 0x0D891E2A;
const DWORD WNF_GPOL_SYSTEM_CHANGES_LO = 0xA3BC0875;
+ BOOL ret = FALSE;
HMODULE ntdll = LoadLibraryA("ntdll.dll");
if (ntdll == NULL)
@@ -1081,16 +1082,19 @@
RtlPublishWnfStateData = (publish_fn_t)GetProcAddress(ntdll, "RtlPublishWnfStateData");
if (RtlPublishWnfStateData == NULL)
{
- return FALSE;
+ goto cleanup;
}
if (RtlPublishWnfStateData(WNF_GPOL_SYSTEM_CHANGES_LO, WNF_GPOL_SYSTEM_CHANGES_HI, 0, 0, 0, 0)
!= ERROR_SUCCESS)
{
- return FALSE;
+ goto cleanup;
}
- return TRUE;
+ ret = TRUE;
+cleanup:
+ FreeLibrary(ntdll);
+ return ret;
}
/**
@@ -1106,6 +1110,7 @@
unsigned int Length, INT64 ExplicitScope);
publish_fn_t RtlPublishWnfStateData;
const INT64 WNF_GPOL_SYSTEM_CHANGES = 0x0D891E2AA3BC0875;
+ BOOL ret = FALSE;
HMODULE ntdll = LoadLibraryA("ntdll.dll");
if (ntdll == NULL)
@@ -1116,15 +1121,18 @@
RtlPublishWnfStateData = (publish_fn_t)GetProcAddress(ntdll, "RtlPublishWnfStateData");
if (RtlPublishWnfStateData == NULL)
{
- return FALSE;
+ goto cleanup;
}
if (RtlPublishWnfStateData(WNF_GPOL_SYSTEM_CHANGES, 0, 0, 0, 0) != ERROR_SUCCESS)
{
- return FALSE;
+ goto cleanup;
}
- return TRUE;
+ ret = TRUE;
+cleanup:
+ FreeLibrary(ntdll);
+ return ret;
}
/**