]> Savannah Git Hosting - gnulib.git/commitdiff
relocatable-lib-lgpl: Fix a memory leak related to a Windows DLL.
authorBruno Haible <bruno@clisp.org>
Sun, 8 Aug 2021 17:11:31 +0000 (19:11 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 8 Aug 2021 17:11:31 +0000 (19:11 +0200)
Reported by Jonathan Boeing <jonathan@claws-mail.org> in
<https://lists.gnu.org/archive/html/bug-gnulib/2021-08/msg00048.html>.

* lib/relocatable.c (DllMain): Avoid memory leak in a special case
of repeated attach/detach.

ChangeLog
lib/relocatable.c

index fd21a946c0830a8b7ebdaf051e347755c3e3574a..dba60b9191523b60f93e59b052ffa48f1705fa49 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2021-08-08  Bruno Haible  <bruno@clisp.org>
+
+       relocatable-lib-lgpl: Fix a memory leak related to a Windows DLL.
+       Reported by Jonathan Boeing <jonathan@claws-mail.org> in
+       <https://lists.gnu.org/archive/html/bug-gnulib/2021-08/msg00048.html>.
+       * lib/relocatable.c (DllMain): Avoid memory leak in a special case
+       of repeated attach/detach.
+
 2021-08-08  Bruno Haible  <bruno@clisp.org>
 
        fopen: Fix link error on native Windows.
index ababc350116b7d394075068b2a8f80bc113d0adc..a6829127b48db49d1937db1e475690f9a2f56ccd 100644 (file)
@@ -323,7 +323,10 @@ static char *shared_library_fullname;
    supports longer file names
    (see <https://cygwin.com/ml/cygwin/2011-01/msg00410.html>).  */
 
-/* Determine the full pathname of the shared library when it is loaded.  */
+/* Determine the full pathname of the shared library when it is loaded.
+
+   Documentation:
+   <https://docs.microsoft.com/en-us/windows/win32/dlls/dllmain>  */
 
 BOOL WINAPI
 DllMain (HINSTANCE module_handle, DWORD event, LPVOID reserved)
@@ -343,7 +346,13 @@ DllMain (HINSTANCE module_handle, DWORD event, LPVOID reserved)
         /* Shouldn't happen.  */
         return FALSE;
 
-      shared_library_fullname = strdup (location);
+      /* Avoid a memory leak when the same DLL get attached, detached,
+         attached, detached, and so on.  This happens e.g. when a spell
+         checker DLL is used repeatedly by a mail program.  */
+      if (!(shared_library_fullname != NULL
+            && strcmp (shared_library_fullname, location) == 0))
+        /* Remember the full pathname of the shared library.  */
+        shared_library_fullname = strdup (location);
     }
 
   return TRUE;