diff --git a/src/cas/generic/caCommonDef.h b/src/cas/generic/caCommonDef.h index fd728211b..aad85cd64 100644 --- a/src/cas/generic/caCommonDef.h +++ b/src/cas/generic/caCommonDef.h @@ -23,14 +23,6 @@ #define NULL 0 #endif -#ifndef FALSE -#define FALSE 0 -#endif - -#ifndef TRUE -#define TRUE 1 -#endif - #ifndef NELEMENTS #define NELEMENTS(array) (sizeof(array)/sizeof((array)[0])) #endif diff --git a/src/gdd/gddI.h b/src/gdd/gddI.h index 1d2a6c2d1..20be72d5b 100644 --- a/src/gdd/gddI.h +++ b/src/gdd/gddI.h @@ -142,17 +142,15 @@ inline gddStatus gdd::reference(void) const { fprintf(stderr,"reference of gdd marked \"no-referencing\" ignored!!\n"); gddAutoPrint("gdd::reference()",gddErrorNotAllowed); - rc=gddErrorNotAllowed; + rc = gddErrorNotAllowed; + } + else if ( this->ref_cnt < 0xffffffff ) { + this->ref_cnt++; // X aCC 818 } else { - if ( this->ref_cnt >= 0xffffffff ) { - fprintf(stderr,"gdd reference count overflow!!\n"); - gddAutoPrint("gdd::reference()",gddErrorOverflow); - rc=gddErrorOverflow; - } - else { - this->ref_cnt++; // X aCC 818 - } + fprintf(stderr,"gdd reference count overflow!!\n"); + gddAutoPrint("gdd::reference()",gddErrorOverflow); + rc=gddErrorOverflow; } return rc; } @@ -161,23 +159,27 @@ inline gddStatus gdd::unreference(void) const { int rc=0; - if(ref_cnt==0u) + if ( ref_cnt > 1u ) { + ref_cnt--; + } + else if ( ref_cnt == 0u ) { fprintf(stderr,"gdd reference count underflow!!\n"); gddAutoPrint("gdd::unreference()",gddErrorUnderflow); rc=gddErrorUnderflow; } - else if(--ref_cnt<=0u) // X aCC 818 - { - if(isManaged()) - { + else { + if ( isManaged() ) { // managed dd always destroys the entire thing - ref_cnt=1; if(destruct) destruct->destroy((void *)this); destruct=NULL; } - else if(!isFlat()) + else if(!isFlat()) { + // hopefully catch ref/unref missmatches while + // gdd is on free list + ref_cnt = 0; delete this; + } } return rc; } diff --git a/src/gdd/smartGDDPointer.cc b/src/gdd/smartGDDPointer.cc index a72ad4f1b..d95b5c623 100644 --- a/src/gdd/smartGDDPointer.cc +++ b/src/gdd/smartGDDPointer.cc @@ -21,24 +21,18 @@ // // smartGDDPointer::set() // -void smartConstGDDPointer::set (const gdd *pNewValue) +void smartConstGDDPointer::set ( const gdd * pNewValue ) { - int gddStatus; - // - // dont change the ref count (and - // potentially unref a gdd that we are - // still using if the pointer isnt changing - // - if ( this->pConstValue == pNewValue ) { - return; - } - if ( this->pConstValue != NULL ) { - gddStatus = this->pConstValue->unreference(); - assert ( ! gddStatus ); - } - this->pConstValue = pNewValue; - if ( this->pConstValue != NULL ) { - gddStatus = this->pConstValue->reference(); - assert ( ! gddStatus ); - } + if ( pNewValue != this->pConstValue ) { + int gddStatus; + if ( pNewValue != NULL ) { + gddStatus = pNewValue->reference(); + assert ( ! gddStatus ); + } + if ( this->pConstValue != NULL ) { + gddStatus = this->pConstValue->unreference(); + assert ( ! gddStatus ); + } + this->pConstValue = pNewValue; + } }