[PATCH] Cygwin: dlfcn: fix ENOENT in dlclose

Yuyi Wang Strawberry_Str@hotmail.com
Sun Mar 30 15:00:35 GMT 2025


dlclose tries to decrease the ref count of the dll* entry, but a new dll
opened by dlopen doesn't create a new dll* entry.
---
 winsup/cygwin/dlfcn.cc | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/winsup/cygwin/dlfcn.cc b/winsup/cygwin/dlfcn.cc
index fb7052473..3093ec1be 100644
--- a/winsup/cygwin/dlfcn.cc
+++ b/winsup/cygwin/dlfcn.cc
@@ -350,14 +350,15 @@ dlclose (void *handle)
     {
       /* reference counting */
       dll *d = dlls.find (handle);
-      if (!d || d->count <= 0)
+      if (d && d->count <= 0)
 	{
 	  errno = ENOENT;
 	  ret = -1;
 	}
       else
 	{
-	  --d->count;
+	  if (d)
+	    --d->count;
 	  if (!FreeLibrary ((HMODULE) handle))
 	    {
 	      __seterrno ();
-- 
2.48.1.windows.1-2



More information about the Cygwin-patches mailing list