https://bugs.documentfoundation.org/show_bug.cgi?id=89855

            Bug ID: 89855
           Summary: Data race in cppu_detail_getUnoType
           Product: LibreOffice
           Version: 4.1.4.2 release
          Hardware: x86-64 (AMD64)
                OS: Linux (All)
            Status: UNCONFIRMED
          Severity: major
          Priority: medium
         Component: sdk
          Assignee: [email protected]
          Reporter: [email protected]

Header files generated by cppumaker contain this code (example from
XPropValue.hpp):

inline ::com::sun::star::uno::Type const &
cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::ooo::vba::XPropValue const *) {
    static typelib_TypeDescriptionReference * the_type = 0;
    if ( !the_type )
    {
        typelib_static_type_init( &the_type, typelib_TypeClass_INTERFACE,
"ooo.vba.XPropValue" );
    }
    return * reinterpret_cast< ::com::sun::star::uno::Type * >( &the_type );
}


Access to the the_type static variable is not threadsafe and can produce a data
race.

Interestingly, cppu_detail_getUnoType is implemented differently in
XAdapter.hpp (and possibly others):
nline ::com::sun::star::uno::Type const &
cppu_detail_getUnoType(SAL_UNUSED_PARAMETER css::uno::XAdapter const *) {
    const ::com::sun::star::uno::Type &rRet = *detail::theXAdapterType::get();
    // End inline typedescription generation
    static bool bInitStarted = false;
    if (!bInitStarted)
    {
        ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
...

I'd suggest to either adapt cppumaker to generate similar code than in
XAdapter.hpp, or use the (gcc only?) feature of threadsafe static variable
init:
{
    static typelib_TypeDescriptionReference * the_type =
typelib_static_type_init_( typelib_TypeClass_INTERFACE, "ooo.vba.XPropValue" );
    return * reinterpret_cast< ::com::sun::star::uno::Type * >( &the_type );
}

And of course adding a typelib_static_type_init method with a return value.

-- 
You are receiving this mail because:
You are the assignee for the bug.
_______________________________________________
Libreoffice-bugs mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/libreoffice-bugs

Reply via email to