Fix a memory leak if compiled with Windows locale support
authorDaniel Veillard <veillard@redhat.com>
Mon, 28 Feb 2011 01:54:15 +0000 (09:54 +0800)
committerDaniel Veillard <veillard@redhat.com>
Mon, 28 Feb 2011 01:54:15 +0000 (09:54 +0800)
Ralf Junker <ralfjunker@gmx.de> pointed out a ouple of leaks in the
Windows locale support:
* libxslt/xslt.c: add cleanup code for the mutex in xsltUninit()
* libxslt/xsltlocale.c libxslt/xsltlocale.h: add a new cleanup function
  xsltFreeLocales
* libxslt/extensions.c: add a call to xsltFreeLocales in xsltCleanupGlobals

libxslt/extensions.c
libxslt/xslt.c
libxslt/xsltlocale.c
libxslt/xsltlocale.h

index 6187b7a..f6f021e 100644 (file)
@@ -2289,6 +2289,7 @@ xsltCleanupGlobals(void)
 
     xmlFreeMutex(xsltExtMutex);
     xsltExtMutex = NULL;
+    xsltFreeLocales();
     xsltUninit();
 }
 
index 8e8c414..6293bb3 100644 (file)
@@ -243,6 +243,10 @@ xsltInit (void) {
  */
 void
 xsltUninit (void) {
+#ifdef XSLT_LOCALE_WINAPI
+    xmlFreeRMutex(xsltLocaleMutex);
+    xsltLocaleMutex = NULL;
+#endif
     initialized = 0;
 }
 
index 2caa2ec..70a0b99 100644 (file)
@@ -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
  *
index 59343b0..9af4adc 100644 (file)
@@ -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__ */