diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2015-11-02 10:50:24 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2015-11-02 10:50:24 +0100 |
commit | f570f837d65c9ee79a10be823c3dc28febdebfc8 (patch) | |
tree | e626995e77577ce08e65332ce0b891a91c6ae6f6 | |
parent | 4e4ea4bc733dc62e6c06eb42574ea0c5b0e5b826 (diff) |
Avoid ASan new-delete-type-mismatch with -fsized-deallocation
...where "subclasses" of typelib_TypeDescription are deleted non-
polymorphically
Change-Id: I708d245e12d2e2159e9df60b61d1b37801083651
-rw-r--r-- | cppu/source/typelib/typelib.cxx | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/cppu/source/typelib/typelib.cxx b/cppu/source/typelib/typelib.cxx index 238b4daa393e..2c274bdc8891 100644 --- a/cppu/source/typelib/typelib.cxx +++ b/cppu/source/typelib/typelib.cxx @@ -449,6 +449,14 @@ static inline void typelib_typedescription_initTables( namespace { +template<typename T> T * allocTypeDescription() { + return reinterpret_cast<T *>(new char[sizeof (T)]); +} + +void freeTypeDescription(typelib_TypeDescription const * desc) { + delete[] reinterpret_cast<char const *>(desc); +} + // In some situations (notably typelib_typedescription_newInterfaceMethod and // typelib_typedescription_newInterfaceAttribute), only the members nMembers, // ppMembers, nAllMembers, and ppAllMembers of an incomplete interface type @@ -568,7 +576,7 @@ extern "C" void SAL_CALL typelib_typedescription_newEmpty( { case typelib_TypeClass_SEQUENCE: { - typelib_IndirectTypeDescription * pTmp = new typelib_IndirectTypeDescription(); + auto pTmp = allocTypeDescription<typelib_IndirectTypeDescription>(); pRet = &pTmp->aBase; #if OSL_DEBUG_LEVEL > 1 osl_atomic_increment( &Init::get().nIndirectTypeDescriptionCount ); @@ -580,8 +588,7 @@ extern "C" void SAL_CALL typelib_typedescription_newEmpty( case typelib_TypeClass_STRUCT: { // FEATURE_EMPTYCLASS - typelib_StructTypeDescription * pTmp; - pTmp = new typelib_StructTypeDescription(); + auto pTmp = allocTypeDescription<typelib_StructTypeDescription>(); pRet = &pTmp->aBase.aBase; #if OSL_DEBUG_LEVEL > 1 osl_atomic_increment( &Init::get().nCompoundTypeDescriptionCount ); @@ -598,8 +605,7 @@ extern "C" void SAL_CALL typelib_typedescription_newEmpty( case typelib_TypeClass_EXCEPTION: { // FEATURE_EMPTYCLASS - typelib_CompoundTypeDescription * pTmp; - pTmp = new typelib_CompoundTypeDescription(); + auto pTmp = allocTypeDescription<typelib_CompoundTypeDescription>(); pRet = &pTmp->aBase; #if OSL_DEBUG_LEVEL > 1 osl_atomic_increment( &Init::get().nCompoundTypeDescriptionCount ); @@ -614,7 +620,7 @@ extern "C" void SAL_CALL typelib_typedescription_newEmpty( case typelib_TypeClass_ENUM: { - typelib_EnumTypeDescription * pTmp = new typelib_EnumTypeDescription(); + auto pTmp = allocTypeDescription<typelib_EnumTypeDescription>(); pRet = &pTmp->aBase; #if OSL_DEBUG_LEVEL > 1 osl_atomic_increment( &Init::get().nEnumTypeDescriptionCount ); @@ -628,7 +634,8 @@ extern "C" void SAL_CALL typelib_typedescription_newEmpty( case typelib_TypeClass_INTERFACE: { - typelib_InterfaceTypeDescription * pTmp = new typelib_InterfaceTypeDescription(); + auto pTmp = allocTypeDescription< + typelib_InterfaceTypeDescription>(); pRet = &pTmp->aBase; #if OSL_DEBUG_LEVEL > 1 osl_atomic_increment( &Init::get().nInterfaceTypeDescriptionCount ); @@ -648,7 +655,8 @@ extern "C" void SAL_CALL typelib_typedescription_newEmpty( case typelib_TypeClass_INTERFACE_METHOD: { - typelib_InterfaceMethodTypeDescription * pTmp = new typelib_InterfaceMethodTypeDescription(); + auto pTmp = allocTypeDescription< + typelib_InterfaceMethodTypeDescription>(); pRet = &pTmp->aBase.aBase; #if OSL_DEBUG_LEVEL > 1 osl_atomic_increment( &Init::get().nInterfaceMethodTypeDescriptionCount ); @@ -667,7 +675,8 @@ extern "C" void SAL_CALL typelib_typedescription_newEmpty( case typelib_TypeClass_INTERFACE_ATTRIBUTE: { - typelib_InterfaceAttributeTypeDescription * pTmp = new typelib_InterfaceAttributeTypeDescription(); + auto * pTmp = allocTypeDescription< + typelib_InterfaceAttributeTypeDescription>(); pRet = &pTmp->aBase.aBase; #if OSL_DEBUG_LEVEL > 1 osl_atomic_increment( &Init::get().nInterfaceAttributeTypeDescriptionCount ); @@ -686,7 +695,7 @@ extern "C" void SAL_CALL typelib_typedescription_newEmpty( default: { - pRet = new typelib_TypeDescription(); + pRet = allocTypeDescription<typelib_TypeDescription>(); #if OSL_DEBUG_LEVEL > 1 osl_atomic_increment( &Init::get().nTypeDescriptionCount ); #endif @@ -1462,7 +1471,7 @@ extern "C" void SAL_CALL typelib_typedescription_release( } #endif - delete pTD; + freeTypeDescription(pTD); } } |