[vlc-devel] commit: libxml: fix plugin re-entrancy - refs #2541 ( Rémi Denis-Courmont )

git version control git at videolan.org
Fri Feb 20 17:54:31 CET 2009


vlc | branch: master | Rémi Denis-Courmont <rdenis at simphalempin.com> | Fri Feb 20 18:52:47 2009 +0200| [cf44d7458dcd61fc124e945c4284448d6ab88ff5] | committer: Rémi Denis-Courmont 

libxml: fix plugin re-entrancy - refs #2541

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=cf44d7458dcd61fc124e945c4284448d6ab88ff5
---

 modules/misc/xml/libxml.c |   17 +++++++++++++++--
 1 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/modules/misc/xml/libxml.c b/modules/misc/xml/libxml.c
index f4bad58..28a6696 100644
--- a/modules/misc/xml/libxml.c
+++ b/modules/misc/xml/libxml.c
@@ -67,6 +67,9 @@ static void CatalogLoad( xml_t *, const char * );
 static void CatalogAdd( xml_t *, const char *, const char *, const char * );
 static int StreamRead( void *p_context, char *p_buffer, int i_buffer );
 
+static unsigned refs = 0;
+static vlc_mutex_t lock = VLC_STATIC_MUTEX;
+
 /*****************************************************************************
  * Module initialization
  *****************************************************************************/
@@ -74,7 +77,13 @@ static int Open( vlc_object_t *p_this )
 {
     xml_t *p_xml = (xml_t *)p_this;
 
-    xmlInitParser();
+    if( !xmlHasFeature( XML_WITH_THREAD ) )
+        return VLC_EGENERIC;
+
+    vlc_mutex_lock( &lock );
+    if( refs++ == 0 )
+        xmlInitParser();
+    vlc_mutex_unlock( &lock );
 
     p_xml->pf_reader_create = ReaderCreate;
     p_xml->pf_reader_delete = ReaderDelete;
@@ -90,7 +99,11 @@ static int Open( vlc_object_t *p_this )
  *****************************************************************************/
 static void Close( vlc_object_t *p_this )
 {
-    xmlCleanupParser();
+    vlc_mutex_lock( &lock );
+    if( --refs == 0 )
+        xmlCleanupParser();
+    vlc_mutex_unlock( &lock );
+
     VLC_UNUSED(p_this);
     return;
 }




More information about the vlc-devel mailing list