Avoid ASan new-delete-type-mismatch with -fsized-deallocation

...where "subclasses" of typelib_TypeDescription are deleted non-
polymorphically

Change-Id: I708d245e12d2e2159e9df60b61d1b37801083651
This commit is contained in:
Stephan Bergmann 2015-11-02 10:50:24 +01:00
parent 4e4ea4bc73
commit f570f837d6

View File

@ -449,6 +449,14 @@ static inline void typelib_typedescription_initTables(
namespace { 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 // In some situations (notably typelib_typedescription_newInterfaceMethod and
// typelib_typedescription_newInterfaceAttribute), only the members nMembers, // typelib_typedescription_newInterfaceAttribute), only the members nMembers,
// ppMembers, nAllMembers, and ppAllMembers of an incomplete interface type // 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: case typelib_TypeClass_SEQUENCE:
{ {
typelib_IndirectTypeDescription * pTmp = new typelib_IndirectTypeDescription(); auto pTmp = allocTypeDescription<typelib_IndirectTypeDescription>();
pRet = &pTmp->aBase; pRet = &pTmp->aBase;
#if OSL_DEBUG_LEVEL > 1 #if OSL_DEBUG_LEVEL > 1
osl_atomic_increment( &Init::get().nIndirectTypeDescriptionCount ); osl_atomic_increment( &Init::get().nIndirectTypeDescriptionCount );
@ -580,8 +588,7 @@ extern "C" void SAL_CALL typelib_typedescription_newEmpty(
case typelib_TypeClass_STRUCT: case typelib_TypeClass_STRUCT:
{ {
// FEATURE_EMPTYCLASS // FEATURE_EMPTYCLASS
typelib_StructTypeDescription * pTmp; auto pTmp = allocTypeDescription<typelib_StructTypeDescription>();
pTmp = new typelib_StructTypeDescription();
pRet = &pTmp->aBase.aBase; pRet = &pTmp->aBase.aBase;
#if OSL_DEBUG_LEVEL > 1 #if OSL_DEBUG_LEVEL > 1
osl_atomic_increment( &Init::get().nCompoundTypeDescriptionCount ); osl_atomic_increment( &Init::get().nCompoundTypeDescriptionCount );
@ -598,8 +605,7 @@ extern "C" void SAL_CALL typelib_typedescription_newEmpty(
case typelib_TypeClass_EXCEPTION: case typelib_TypeClass_EXCEPTION:
{ {
// FEATURE_EMPTYCLASS // FEATURE_EMPTYCLASS
typelib_CompoundTypeDescription * pTmp; auto pTmp = allocTypeDescription<typelib_CompoundTypeDescription>();
pTmp = new typelib_CompoundTypeDescription();
pRet = &pTmp->aBase; pRet = &pTmp->aBase;
#if OSL_DEBUG_LEVEL > 1 #if OSL_DEBUG_LEVEL > 1
osl_atomic_increment( &Init::get().nCompoundTypeDescriptionCount ); osl_atomic_increment( &Init::get().nCompoundTypeDescriptionCount );
@ -614,7 +620,7 @@ extern "C" void SAL_CALL typelib_typedescription_newEmpty(
case typelib_TypeClass_ENUM: case typelib_TypeClass_ENUM:
{ {
typelib_EnumTypeDescription * pTmp = new typelib_EnumTypeDescription(); auto pTmp = allocTypeDescription<typelib_EnumTypeDescription>();
pRet = &pTmp->aBase; pRet = &pTmp->aBase;
#if OSL_DEBUG_LEVEL > 1 #if OSL_DEBUG_LEVEL > 1
osl_atomic_increment( &Init::get().nEnumTypeDescriptionCount ); osl_atomic_increment( &Init::get().nEnumTypeDescriptionCount );
@ -628,7 +634,8 @@ extern "C" void SAL_CALL typelib_typedescription_newEmpty(
case typelib_TypeClass_INTERFACE: case typelib_TypeClass_INTERFACE:
{ {
typelib_InterfaceTypeDescription * pTmp = new typelib_InterfaceTypeDescription(); auto pTmp = allocTypeDescription<
typelib_InterfaceTypeDescription>();
pRet = &pTmp->aBase; pRet = &pTmp->aBase;
#if OSL_DEBUG_LEVEL > 1 #if OSL_DEBUG_LEVEL > 1
osl_atomic_increment( &Init::get().nInterfaceTypeDescriptionCount ); osl_atomic_increment( &Init::get().nInterfaceTypeDescriptionCount );
@ -648,7 +655,8 @@ extern "C" void SAL_CALL typelib_typedescription_newEmpty(
case typelib_TypeClass_INTERFACE_METHOD: case typelib_TypeClass_INTERFACE_METHOD:
{ {
typelib_InterfaceMethodTypeDescription * pTmp = new typelib_InterfaceMethodTypeDescription(); auto pTmp = allocTypeDescription<
typelib_InterfaceMethodTypeDescription>();
pRet = &pTmp->aBase.aBase; pRet = &pTmp->aBase.aBase;
#if OSL_DEBUG_LEVEL > 1 #if OSL_DEBUG_LEVEL > 1
osl_atomic_increment( &Init::get().nInterfaceMethodTypeDescriptionCount ); osl_atomic_increment( &Init::get().nInterfaceMethodTypeDescriptionCount );
@ -667,7 +675,8 @@ extern "C" void SAL_CALL typelib_typedescription_newEmpty(
case typelib_TypeClass_INTERFACE_ATTRIBUTE: case typelib_TypeClass_INTERFACE_ATTRIBUTE:
{ {
typelib_InterfaceAttributeTypeDescription * pTmp = new typelib_InterfaceAttributeTypeDescription(); auto * pTmp = allocTypeDescription<
typelib_InterfaceAttributeTypeDescription>();
pRet = &pTmp->aBase.aBase; pRet = &pTmp->aBase.aBase;
#if OSL_DEBUG_LEVEL > 1 #if OSL_DEBUG_LEVEL > 1
osl_atomic_increment( &Init::get().nInterfaceAttributeTypeDescriptionCount ); osl_atomic_increment( &Init::get().nInterfaceAttributeTypeDescriptionCount );
@ -686,7 +695,7 @@ extern "C" void SAL_CALL typelib_typedescription_newEmpty(
default: default:
{ {
pRet = new typelib_TypeDescription(); pRet = allocTypeDescription<typelib_TypeDescription>();
#if OSL_DEBUG_LEVEL > 1 #if OSL_DEBUG_LEVEL > 1
osl_atomic_increment( &Init::get().nTypeDescriptionCount ); osl_atomic_increment( &Init::get().nTypeDescriptionCount );
#endif #endif
@ -1462,7 +1471,7 @@ extern "C" void SAL_CALL typelib_typedescription_release(
} }
#endif #endif
delete pTD; freeTypeDescription(pTD);
} }
} }