diff --git a/flaim/src/flaim.h b/flaim/src/flaim.h index 6461ff1..cf75b6b 100644 --- a/flaim/src/flaim.h +++ b/flaim/src/flaim.h @@ -5481,6 +5481,9 @@ FLMINT Release( FLMBOOL bMutexLocked); + static void objectAllocInit( + void * pvAlloc); + void * parent( FlmField * pField); diff --git a/flaim/src/flfixed.h b/flaim/src/flfixed.h index 607cf1f..e282915 100644 --- a/flaim/src/flfixed.h +++ b/flaim/src/flfixed.h @@ -138,6 +138,9 @@ typedef void (* FLM_RELOC_FUNC)( typedef FLMBOOL (* FLM_CAN_RELOC_FUNC)( void * pvOldAlloc); +typedef void (* FLM_ALLOC_INIT_FUNC)( + void * pvAlloc); + /**************************************************************************** Desc: Class to provide an efficient means of providing many allocations of a fixed size. @@ -199,6 +202,31 @@ public: return( pvCell); } + FINLINE void * allocCell( + FLM_ALLOC_INIT_FUNC fnAllocInit) + { + void * pvCell; + + if( m_phMutex) + { + f_mutexLock( *m_phMutex); + } + + pvCell = getCell(); + + if( pvCell && fnAllocInit) + { + fnAllocInit( pvCell); + } + + if( m_phMutex) + { + f_mutexUnlock( *m_phMutex); + } + + return( pvCell); + } + FINLINE void freeCell( void * ptr) { diff --git a/flaim/src/frec.cpp b/flaim/src/frec.cpp index d3c384a..503a0f3 100644 --- a/flaim/src/frec.cpp +++ b/flaim/src/frec.cpp @@ -86,6 +86,7 @@ FlmRecord::~FlmRecord() gv_FlmSysData.RCacheMgr.pRecBufAlloc->freeBuf( m_uiBufferSize, &m_pucBuffer); } + if( m_pucFieldIdTable) { flmAssert( *((FlmRecord **)m_pucFieldIdTable) == this); @@ -4631,6 +4632,21 @@ void * FlmRecord::locateFieldByPosition( return (getFieldVoid( pField)); } +/**************************************************************************** +Desc: +****************************************************************************/ +void FlmRecord::objectAllocInit( + void * pvAlloc) +{ + // Need to make sure that m_refCnt and m_uiFlags are initialized to zero + // prior to unlocking the mutex. This is so the FLAIM allocator + // doesn't see garbage values that may cause it to relocate the object + // before the constructor has been called. + + ((FlmRecord *)pvAlloc)->m_uiFlags = 0; + ((FlmRecord *)pvAlloc)->m_refCnt = 0; +} + #undef new #undef delete @@ -4645,7 +4661,7 @@ void * FlmRecord::operator new( { F_UNREFERENCED_PARM( uiSize); flmAssert( gv_FlmSysData.RCacheMgr.pRecAlloc->getCellSize() >= uiSize); - return( gv_FlmSysData.RCacheMgr.pRecAlloc->allocCell()); + return( gv_FlmSysData.RCacheMgr.pRecAlloc->allocCell( objectAllocInit)); } /**************************************************************************** @@ -4673,7 +4689,7 @@ void * FlmRecord::operator new( #endif { flmAssert( gv_FlmSysData.RCacheMgr.pRecAlloc->getCellSize() >= uiSize); - return( gv_FlmSysData.RCacheMgr.pRecAlloc->allocCell()); + return( gv_FlmSysData.RCacheMgr.pRecAlloc->allocCell( objectAllocInit)); } #endif