From: Bruno Haible Date: Sun, 8 Aug 2021 17:11:31 +0000 (+0200) Subject: relocatable-lib-lgpl: Fix a memory leak related to a Windows DLL. X-Git-Tag: v1.0~2670 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=51dd05503668d47c0f5b37a9b481d4e3d7463586;p=gnulib.git relocatable-lib-lgpl: Fix a memory leak related to a Windows DLL. Reported by Jonathan Boeing in . * lib/relocatable.c (DllMain): Avoid memory leak in a special case of repeated attach/detach. --- diff --git a/ChangeLog b/ChangeLog index fd21a946c0..dba60b9191 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2021-08-08 Bruno Haible + + relocatable-lib-lgpl: Fix a memory leak related to a Windows DLL. + Reported by Jonathan Boeing in + . + * lib/relocatable.c (DllMain): Avoid memory leak in a special case + of repeated attach/detach. + 2021-08-08 Bruno Haible fopen: Fix link error on native Windows. diff --git a/lib/relocatable.c b/lib/relocatable.c index ababc35011..a6829127b4 100644 --- a/lib/relocatable.c +++ b/lib/relocatable.c @@ -323,7 +323,10 @@ static char *shared_library_fullname; supports longer file names (see ). */ -/* 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: + */ 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;