PATCH: Use FreeLibrary instead of CloseHandle to free Win32 DLL opened with LoadLibraryEx

John Thacker via Gcrypt-devel <[email protected]> Sun, 10 May 2026 10:29:17 -0400
Newsgroups gmane.comp.encryption.gpg.libgcrypt.devel
Message-ID <CAP_QLgoye4ATGU6MpQUaMR0EG_Z4k_L957NkjxDvEdB0d3nF-A@mail.gmail.com>
--===============8314903819883816798==
Content-Type: multipart/alternative; boundary="00000000000026abd10651777564"

--00000000000026abd10651777564
Content-Type: text/plain; charset="UTF-8"

Below is a patch to fix an issue with a recent libgcrypt commit that
opens the Windows "shell32.dll" with LoadLibraryEx but closes it with
CloseHandle instead of the preferred FreeLibrary. This caused problems
running Wireshark under certain circumstances, e.g. under the MSVC
debugger.

Thanks,

John Thacker


>From 5979c49b981142efc2a0a8d67ee65fe62252dad7 Mon Sep 17 00:00:00
2001From: gpotter2 <[email protected]>Date:
Thu, 7 May 2026 00:52:19 +0200Subject: [PATCH] Fix 'Invalid Handle'
crash on Win32--- src/hwfeatures.c | 2 +- 1 file changed, 1
insertion(+), 1 deletion(-)diff --git a/src/hwfeatures.c
b/src/hwfeatures.cindex 1b107e63..34017cf7 100644---
a/src/hwfeatures.c+++ b/src/hwfeatures.c@@ -336,7 +336,7 @@
_gcry_get_sysconfdir (void)               strcat (appdata,
"/GNU/etc/gcrypt/");             }           xfree (buf);-
CloseHandle (handle);+          FreeLibrary(handle);         }
if (!appdata)         appdata = xstrdup
("c:/ProgramData/GNU/etc/gcrypt/");--2.47.0.windows.1

--00000000000026abd10651777564
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div class=3D"gmail_default" style=3D"font-family:arial,sa=
ns-serif"><pre class=3D"gmail-code gmail-highlight" lang=3D"plaintext"><fon=
t face=3D"arial,sans-serif">Below is a patch to fix an issue with a recent =
libgcrypt commit that opens the Windows &quot;shell32.dll&quot; with LoadLi=
braryEx but closes it with CloseHandle instead of the preferred FreeLibrary=
. This caused problems running Wireshark under certain circumstances, e.g. =
under the MSVC debugger.<br><br></font></pre><pre class=3D"gmail-code gmail=
-highlight" lang=3D"plaintext"><font face=3D"arial,sans-serif">Thanks,<br><=
/font></pre><pre class=3D"gmail-code gmail-highlight" lang=3D"plaintext"><f=
ont face=3D"arial,sans-serif">John Thacker</font></pre><pre class=3D"gmail-=
code gmail-highlight" lang=3D"plaintext"><span><br>From 5979c49b981142efc2a=
0a8d67ee65fe62252dad7 Mon Sep 17 00:00:00 2001</span>
<span>From: gpotter2 &lt;<a href=3D"mailto:10530980%[email protected]=
y.github.com">[email protected]</a>&gt;</span>
<span>Date: Thu, 7 May 2026 00:52:19 +0200</span>
<span>Subject: [PATCH] Fix &#39;Invalid Handle&#39; crash on Win32</span>
<span></span>
<span>---</span>
<span> src/hwfeatures.c | 2 +-</span>
<span> 1 file changed, 1 insertion(+), 1 deletion(-)</span>
<span></span>
<span>diff --git a/src/hwfeatures.c b/src/hwfeatures.c</span>
<span>index 1b107e63..34017cf7 100644</span>
<span>--- a/src/hwfeatures.c</span>
<span>+++ b/src/hwfeatures.c</span>
<span>@@ -336,7 +336,7 @@ _gcry_get_sysconfdir (void)</span>
<span>               strcat (appdata, &quot;/GNU/etc/gcrypt/&quot;);</span>
<span>             }</span>
<span>           xfree (buf);</span>
<span>-          CloseHandle (handle);</span>
<span>+          FreeLibrary(handle);</span>
<span>         }</span>
<span>       if (!appdata)</span>
<span>         appdata =3D xstrdup (&quot;c:/ProgramData/GNU/etc/gcrypt/&qu=
ot;);</span>
<span>--</span>
<span>2.47.0.windows.1</span>
</pre><br></div></div>

--00000000000026abd10651777564--


--===============8314903819883816798==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Gcrypt-devel mailing list
[email protected]
https://lists.gnupg.org/mailman/listinfo/gcrypt-devel

--===============8314903819883816798==--