Hi,

See: https://sourceforge.net/p/podofo/mailman/message/35915862/

On Mon, May 3, 2021 at 2:05 PM Christopher Creutzig <ccreu...@mathworks.com>
wrote:

> Hi list,
>
>
>
> PdfEncodingFactory.cpp uses a broken form of double-checked locking
> <https://preshing.com/20130930/double-checked-locking-is-fixed-in-cpp11/>
> to initialize its encoding instances. Not a big deal, as these objects
> don’t do much; technically, that is a data race and can lead to undefined
> behaviour, but realistically, I would be surprised to see anything worse
> than a small memory leak, if even that.
>

It is undefined behaviour in C++. Actually it should cause problems only on
weakly ordered processors like ARM. So you should never see it on x64.


>
> Does PoDoFo require C++11 or newer (where there are simple fixes
> available)? Will it ever?
>
>
If podofo cannot depend on C++11 then I would suggest to use
"single"-checked locking (just remove the first check):

    //if(!s_pWinAnsiEncoding) // First check
    //{
        Util::PdfMutexWrapper wrapper( PdfEncodingFactory::s_mutex );

        if(!s_pWinAnsiEncoding) // Double check
            s_pWinAnsiEncoding = new PdfWinAnsiEncoding();
    //}

    return s_pWinAnsiEncoding;

Another solution would be to use some additional library that provides
atomic primitives for older C++ but I do not think that it would be worth
it in this case.



>
>
>
> Cheers,
>
> Christopher
>
>
>
> The MathWorks GmbH | Friedlandstr.18 | 52064 Aachen | District Court
> Aachen | HRB 8082 | Managing Directors: Bertrand Dissler, Steven D. Barbo,
> Jeanne O’Keefe
>
>
> _______________________________________________
> Podofo-users mailing list
> Podofo-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/podofo-users
>
_______________________________________________
Podofo-users mailing list
Podofo-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/podofo-users

Reply via email to