[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] relocatable: free memory in DLL_PROCESS_DETACH
From: |
Jonathan Boeing |
Subject: |
[PATCH] relocatable: free memory in DLL_PROCESS_DETACH |
Date: |
Wed, 4 Aug 2021 17:31:31 -0700 |
Hi,
Claws Mail uses the Enchant spell checking library, which we build with
relocatable support for Windows.
Running with app verifier enabled caught a memory leak in
lib/relocatable.c. The memory allocated in DllMain() by:
shared_library_fullname = strdup (location);
is never freed. _DLL_InitTerm() looks like it has the same issue, and
find_shared_library_fullname() seems to have a similar issue with the
call to getline().
This is noticeable in Claws because we load/unload Enchant when we
open/close a message compose window.
This patch addresses the Windows case by freeing the memory in
DLL_PROCESS_DETACH. It also initializes shared_library_fullname to NULL
so that it doesn't try to free an uninitialized pointer in the
unexpected situation of something failing in DLL_PROCESS_ATTACH.
From 9175cefe7ab2da7ff215982f43d5de353c3be7a7 Mon Sep 17 00:00:00 2001
From: Jonathan Boeing <jonathan@claws-mail.org>
Date: Wed, 4 Aug 2021 17:12:37 -0700
Subject: [PATCH] relocatable: free memory in DLL_PROCESS_DETACH
---
lib/relocatable.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/lib/relocatable.c b/lib/relocatable.c
index ababc3501..b797e324c 100644
--- a/lib/relocatable.c
+++ b/lib/relocatable.c
@@ -314,7 +314,7 @@ compute_curr_prefix (const char *orig_installprefix,
#if defined PIC && defined INSTALLDIR && ENABLE_COSTLY_RELOCATABLE
/* Full pathname of shared library, or NULL. */
-static char *shared_library_fullname;
+static char *shared_library_fullname = NULL;
#if defined _WIN32 && !defined __CYGWIN__
/* Native Windows only.
@@ -345,6 +345,11 @@ DllMain (HINSTANCE module_handle, DWORD event,
LPVOID reserved)
shared_library_fullname = strdup (location);
}
+ else if (event == DLL_PROCESS_DETACH)
+ {
+ if (shared_library_fullname != NULL)
+ free(shared_library_fullname);
+ }
return TRUE;
}
--
2.20.1
- [PATCH] relocatable: free memory in DLL_PROCESS_DETACH,
Jonathan Boeing <=