summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2017-09-16 22:16:14 +0200
committerMiklos Vajna <vmiklos@collabora.co.uk>2017-09-29 18:12:27 +0200
commit36535c2bef619b3a4090f6f880b975cb6d4dcb11 (patch)
treed29906322ada780f1057a48a9c09d17e65a308ff
parent205677c88cb01e2bbee278443867baed2c89e5fe (diff)
LibreOfficeKitInit.h: release memory after lok_dlerror() on Windows
When _WIN32 is defined, lok_dlerror() uses FormatMessageA() call with FORMAT_MESSAGE_ALLOCATE_BUFFER flag [1] to get returned error string. This string is required to be released after use with LocalFree() (or HeapFree(), since LocalFree() is not available in recent SDKs). However, there is no mention in the header that this is required, nor lok_dlopen() that uses it does any cleanup. If the calling application is expected to be terminated in case of error, then that is no problem; but the header might be used in any external client application which we know nothing of. This adds corresponding cleanup function. Change-Id: I1f14cc5d9e10fe086c3646faaf0e19f2a7a6dd56 Reviewed-on: https://gerrit.libreoffice.org/42360 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
-rw-r--r--include/LibreOfficeKit/LibreOfficeKitInit.h21
1 files changed, 19 insertions, 2 deletions
diff --git a/include/LibreOfficeKit/LibreOfficeKitInit.h b/include/LibreOfficeKit/LibreOfficeKitInit.h
index 1e34e608d6ba..73e2bbb83dfd 100644
--- a/include/LibreOfficeKit/LibreOfficeKitInit.h
+++ b/include/LibreOfficeKit/LibreOfficeKitInit.h
@@ -57,6 +57,13 @@ extern "C"
return dlerror();
}
+ // This function must be called to release memory allocated by lok_dlerror()
+ static void lok_dlerror_free(char *pErrMessage)
+ {
+ (void)pErrMessage;
+ // Do nothing for return of dlerror()
+ }
+
static void extendUnoPath(const char *pPath)
{
(void)pPath;
@@ -97,6 +104,12 @@ extern "C"
return buf;
}
+ // This function must be called to release memory allocated by lok_dlerror()
+ static void lok_dlerror_free(char *pErrMessage)
+ {
+ HeapFree(GetProcessHeap(), 0, pErrMessage);
+ }
+
static void *lok_dlsym(void *Hnd, const char *pName)
{
return reinterpret_cast<void *>(GetProcAddress((HINSTANCE) Hnd, pName));
@@ -198,8 +211,10 @@ static void *lok_dlopen( const char *install_path, char ** _imp_lib )
struct stat st;
if (stat(imp_lib, &st) == 0 && st.st_size > 100)
{
+ char *pErrMessage = lok_dlerror();
fprintf(stderr, "failed to open library '%s': %s\n",
- imp_lib, lok_dlerror());
+ imp_lib, pErrMessage);
+ lok_dlerror_free(pErrMessage);
free(imp_lib);
return NULL;
}
@@ -209,8 +224,10 @@ static void *lok_dlopen( const char *install_path, char ** _imp_lib )
dlhandle = lok_loadlib(imp_lib);
if (!dlhandle)
{
+ char *pErrMessage = lok_dlerror();
fprintf(stderr, "failed to open library '%s': %s\n",
- imp_lib, lok_dlerror());
+ imp_lib, pErrMessage);
+ lok_dlerror_free(pErrMessage);
free(imp_lib);
return NULL;
}