Re: [xslt] Memory leak if compiled with XSLT_LOCALE_WINAPI



On Thu, Feb 24, 2011 at 04:28:13PM +0100, Ralf Junker wrote:
> Daniel, as I see you currently working on the library, would you
> hopefully have some time to look into the following memory leak I
> reported about 2 month ago?

  Yeah, sorry for the delay, basic explanation: I have moved to asia
and my workstation with proper mail filtering rules only arrived end
of last week, and I discovered a lot of backlog mail when restarting
it :-\ . If you have pending patches, please raise them again :-)

[and yes it took nearly 3 months to get my stuff moved to my new location]

> On 17.12.2010 18:28, Ralf Junker wrote:
> 
> > If xsltlocale.c is compiled with XSLT_LOCALE_WINAPI #defined, the
> > following lines allocate memory which is not freed by xsltCleanupGlobals():
> > 
> > xslt.c, 238:       xsltLocaleMutex = xmlNewRMutex();
> > 
> > xsltlocale.c, 508: xsltLocaleList = xmlMalloc(len);
> > 
> > I can see a few places where this could be implemented, but I am not
> > sure which would best suite the existing code base. The following calles
> > are missing IMHO:
> > 
> >     xmlRMutexLock(xsltLocaleMutex);
> >     xmlFree(xsltLocaleList);
> >     xsltLocaleList = NULL;
> >     xmlRMutexUnlock(xsltLocaleMutex);
> > 
> >     xmlFreeRMutex(xsltLocaleMutex);
> >     xsltLocaleMutex = NULL;
> > 
> > Could anyone point me to the correct place?

  xsltCleanupGlobals() calls xsltUninit() which is the symetric fuction
to xsltInit where xsltLocaleMutex is allocated so that's the right place
for the last chunk I think

  The first block should really be added as part of the xsltlocale.c
module, but since there is no global uninitialization function, this
need to be added.

  I end up the the following patch, but since I don't have any Windows
development environment, I can't really check it, could you give it a
try ?

  thanks !

Daniel


-- 
Daniel Veillard      | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
daniel veillard com  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/
diff --git a/libxslt/extensions.c b/libxslt/extensions.c
index 6187b7a..f6f021e 100644
--- a/libxslt/extensions.c
+++ b/libxslt/extensions.c
@@ -2289,6 +2289,7 @@ xsltCleanupGlobals(void)
 
     xmlFreeMutex(xsltExtMutex);
     xsltExtMutex = NULL;
+    xsltFreeLocales();
     xsltUninit();
 }
 
diff --git a/libxslt/xslt.c b/libxslt/xslt.c
index 8e8c414..6293bb3 100644
--- a/libxslt/xslt.c
+++ b/libxslt/xslt.c
@@ -243,6 +243,10 @@ xsltInit (void) {
  */
 void
 xsltUninit (void) {
+#ifdef XSLT_LOCALE_WINAPI
+    xmlFreeRMutex(xsltLocaleMutex);
+    xsltLocaleMutex = NULL;
+#endif
     initialized = 0;
 }
 
diff --git a/libxslt/xsltlocale.c b/libxslt/xsltlocale.c
index 2caa2ec..70a0b99 100644
--- a/libxslt/xsltlocale.c
+++ b/libxslt/xsltlocale.c
@@ -67,6 +67,21 @@ static void xsltEnumSupportedLocales(void);
 #endif
 
 /**
+ * xsltFreeLocales:
+ *
+ * Cleanup function for the locale support on shutdown
+ */
+void
+xsltFreeLocales(void) {
+#ifdef XSLT_LOCALE_WINAPI
+    xmlRMutexLock(xsltLocaleMutex);
+    xmlFree(xsltLocaleList);
+    xsltLocaleList = NULL;
+    xmlRMutexUnlock(xsltLocaleMutex);
+#endif
+}
+
+/**
  * xsltNewLocale:
  * @languageTag: RFC 3066 language tag
  *
diff --git a/libxslt/xsltlocale.h b/libxslt/xsltlocale.h
index 59343b0..9af4adc 100644
--- a/libxslt/xsltlocale.h
+++ b/libxslt/xsltlocale.h
@@ -53,5 +53,6 @@ xsltLocale xsltNewLocale(const xmlChar *langName);
 void xsltFreeLocale(xsltLocale locale);
 xsltLocaleChar *xsltStrxfrm(xsltLocale locale, const xmlChar *string);
 int xsltLocaleStrcmp(xsltLocale locale, const xsltLocaleChar *str1, const xsltLocaleChar *str2);
+void xsltFreeLocales(void);
 
 #endif /* __XML_XSLTLOCALE_H__ */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]