[vlc-devel] [PATCH 1/3] misc/xml: remove useless code replacing it with a comment

Marvin Scholz epirat07 at gmail.com
Wed Sep 23 20:52:43 CEST 2020


Instead of the rather weird, effectively commented-out code, remove
it and add a comment explaining why xmlCleanupParser can't be called
for future reference.
---
 modules/misc/xml/libxml.c | 34 +++++++++++++++++++++++-----------
 1 file changed, 23 insertions(+), 11 deletions(-)

diff --git a/modules/misc/xml/libxml.c b/modules/misc/xml/libxml.c
index 14dd887532f..e077139be7f 100644
--- a/modules/misc/xml/libxml.c
+++ b/modules/misc/xml/libxml.c
@@ -79,13 +79,25 @@ static int Open( vlc_object_t *p_this )
  *****************************************************************************/
 static void Close( vlc_object_t *p_this )
 {
-#ifdef LIBXML_GETS_A_CLUE_ABOUT_REENTRANCY_AND_MEMORY_LEAKS
-    vlc_mutex_lock( &lock );
-    xmlCleanupParser();
-    vlc_mutex_unlock( &lock );
-#endif
+    /* /!\
+     * In theory, xmlCleanupParser() should be called here.
+     * Unfortunately that function is not thread-safe,
+     * operating on global state. So even if we would be
+     * able to know when this module is unloaded, we could
+     * still not call it then, as other libraries or the apps
+     * using libVLC could still use libxml themselves.
+     *
+     * Citing the libxml docs for xmlCleanupParser:
+     *
+     * > If your application is multithreaded or has plugin support
+     * > calling this may crash the application if another thread or
+     * > a plugin is still using libxml2. It's sometimes very hard to
+     * > guess if libxml2 is in use in the application, some libraries
+     * > or plugins may use it without notice. In case of doubt abstain
+     * > from calling this function or do it just before calling exit()
+     * > to avoid leak reports from valgrind!
+     */
     VLC_UNUSED(p_this);
-    return;
 }
 
 /*****************************************************************************
@@ -253,13 +265,13 @@ static void ReaderClose( vlc_object_t *p_this )
     xml_reader_sys_t *p_sys = p_reader->p_sys;
 
     xmlFreeTextReader( p_sys->xml );
-#ifdef LIBXML_GETS_A_CLUE_ABOUT_REENTRANCY_AND_MEMORY_LEAKS
-    vlc_mutex_lock( &lock );
-    xmlCleanupParser();
-    vlc_mutex_unlock( &lock );
-#endif
     free( p_sys->node );
     free( p_sys );
+
+    /* /!\
+     * xmlCleanupParser should but can't be called here,
+     * same reason as in Close() of the main xml module.
+     */
 }
 
 vlc_module_begin ()
-- 
2.24.3 (Apple Git-128)



More information about the vlc-devel mailing list