Hi Michall,

Sorry for the terribly late reply to your email.
I replaced the static arrays with local variables which is totally fine for
these case: https://sourceforge.net/p/podofo/code/1875/

The invalid double checked locking for singletons needs a separate fix
though.

Best regards,
 Dominik

On Tue, Jun 27, 2017 at 10:17 PM, Michal Sudolsky <sudols...@gmail.com>
wrote:

> Hi,
>
> There are many initialised static local variables which is thread-safe
> only in C++11 and above what is ok.
>
> What is not ok is that there are two class member static variables which
> are initialised lazily in some member function.
> These cases are definitely not thread-safe. There should be mutex at least
> or they could be simply declared non-static.
>
> PdfCanvas:
>
>  private:
>>     /** The procset is the same for all
>>      *  PdfContents objects
>>      */
>>     *static **PdfArray s_procset;*
>
>
>
>
>>  const PdfArray & PdfCanvas::GetProcSet()
>> {
>>     if( s_procset.empty() )
>>     {
>>         s_procset.push_back( PdfName( "PDF" ) );
>>         s_procset.push_back( PdfName( "Text" ) );
>>         s_procset.push_back( PdfName( "ImageB" ) );
>>         s_procset.push_back( PdfName( "ImageC" ) );
>>         s_procset.push_back( PdfName( "ImageI" ) );
>>     }
>>     return s_procset;
>> }
>
>
> PdfXObject:
>
>  private:
>>     *static **PdfArray  s_matrix;*
>
>
> void PdfXObject::InitXObject( const PdfRect & rRect, const char*
>> pszPrefix )
>> {
>>     PdfVariant    var;
>>     ostringstream out;
>>     PdfLocaleImbue(out);
>
>
>
>     // Initialize static data
>>     if( s_matrix.empty() )
>>     {
>>         // This matrix is the same for all PdfXObjects so cache it
>>         s_matrix.push_back( PdfVariant( static_cast<pdf_int64>(PODOFO_
>> LL_LITERAL(1)) ) );
>>         s_matrix.push_back( PdfVariant( static_cast<pdf_int64>(PODOFO_
>> LL_LITERAL(0)) ) );
>>         s_matrix.push_back( PdfVariant( static_cast<pdf_int64>(PODOFO_
>> LL_LITERAL(0)) ) );
>>         s_matrix.push_back( PdfVariant( static_cast<pdf_int64>(PODOFO_
>> LL_LITERAL(1)) ) );
>>         s_matrix.push_back( PdfVariant( static_cast<pdf_int64>(PODOFO_
>> LL_LITERAL(0)) ) );
>>         s_matrix.push_back( PdfVariant( static_cast<pdf_int64>(PODOFO_
>> LL_LITERAL(0)) ) );
>>     }
>
>
>
> This DLCP singleton is also not thread-safe on weakly ordered processors:
>
> const PdfEncoding* PdfEncodingFactory::GlobalPdfDocEncodingInstance()
>> {
>>     if(!s_pDocEncoding) // First check
>>     {
>>         Util::PdfMutexWrapper wrapper( PdfEncodingFactory::s_mutex );
>>
>>         if(!s_pDocEncoding) // Double check
>>             s_pDocEncoding = new PdfDocEncoding();
>>     }
>>     return s_pDocEncoding;
>> }
>
> Can be fixed in C++11 http://preshing.com/20130930/double-checked-locking-
> is-fixed-in-cpp11/
>
>
>
> ------------------------------------------------------------
> ------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Podofo-users mailing list
> Podofo-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/podofo-users
>
>
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Podofo-users mailing list
Podofo-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/podofo-users

Reply via email to