[vlc-devel] [PATCH 2/3] misc/xml: only initialize libxml2 once

Marvin Scholz epirat07 at gmail.com
Wed Sep 23 21:18:35 CEST 2020



On 23 Sep 2020, at 21:06, Rémi Denis-Courmont wrote:

> Hi,
>
> Le keskiviikkona 23. syyskuuta 2020, 21.52.44 EEST Marvin Scholz a 
> écrit :
>> ---
>>  modules/misc/xml/libxml.c | 18 +++++++++++-------
>>  1 file changed, 11 insertions(+), 7 deletions(-)
>>
>> diff --git a/modules/misc/xml/libxml.c b/modules/misc/xml/libxml.c
>> index e077139be7f..69637892be9 100644
>> --- a/modules/misc/xml/libxml.c
>> +++ b/modules/misc/xml/libxml.c
>> @@ -52,7 +52,15 @@ static void CatalogAdd( xml_t *p_xml, const char
>> *psz_arg1, (unsigned char*)psz_filename );
>>  }
>>
>> -static vlc_mutex_t lock = VLC_STATIC_MUTEX;
>> +/**************************************************************************
>> *** + * libxml2 initialization
>> +
>> ***************************************************************************
>> **/ +static vlc_once_t xml_init_once_token = VLC_STATIC_ONCE;
>> +
>> +static void vlc_libxml_init_once(void)
>> +{
>> +    xmlInitParser();
>> +}
>
> If another non-concurrent piece of code initializes LibXML, uses it 
> and
> deinitializes it, between two VLC uses then I think that this will 
> break.
>
> AFAIK, calling xmlInitParser() everytime is the least unsafe option.
>

Indeed… Dropped the patch locally.

>>
>>  /**************************************************************************
>> *** * Module initialization
>> @@ -64,9 +72,7 @@ static int Open( vlc_object_t *p_this )
>>      if( !xmlHasFeature( XML_WITH_THREAD ) )
>>          return VLC_EGENERIC;
>>
>> -    vlc_mutex_lock( &lock );
>> -    xmlInitParser();
>> -    vlc_mutex_unlock( &lock );
>> +    vlc_once(&xml_init_once_token, vlc_libxml_init_once);
>>
>>      p_xml->pf_catalog_load = CatalogLoad;
>>      p_xml->pf_catalog_add  = CatalogAdd;
>> @@ -232,9 +238,7 @@ static int ReaderOpen( vlc_object_t *p_this )
>>      if( unlikely(!p_sys) )
>>          return VLC_ENOMEM;
>>
>> -    vlc_mutex_lock( &lock );
>> -    xmlInitParser();
>> -    vlc_mutex_unlock( &lock );
>> +    vlc_once(&xml_init_once_token, vlc_libxml_init_once);
>>
>>      p_libxml_reader = xmlReaderForIO( StreamRead, NULL, 
>> p_reader->p_stream,
>> NULL, NULL, 0 );
>
>
> -- 
> 雷米‧德尼-库尔蒙
> http://www.remlab.net/
>
>
>
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel


More information about the vlc-devel mailing list