sEntityFree() has been called inside our enhanced code 2000 or 3000 times. But NULL pointer checking before freeing the memory is not there.
Like the function has been called as below:
sEntityFree(Entity, ( void** )&StructPtr, sYES );
or
sEntityFree(Entity, ( void** )&StructPtr, sNO );
If I will write it as
if((Entity != NULL) && (StructPtr != NULL))
sEntityFree(Entity, ( void** )&StructPtr, sYES );
Then I have to write this repeatedly as many times the function has been called.
Even I could not change inside the function sEntityFree(), as the code is not with us.
Hence I wanted to write a wraper function like this:
Expand|Select|Wrap|Line Numbers
- int cMemoryFree(sENTITY * Entity,void** StructPtr,sYORN FreeMemory)
- {
- int ret = sSUCCESS; //#define sSUCCESS 0
- if((FreeMemory == sYES) && (Entity != NULL) && (StructPtr != NULL))
- {
- ret = sEntityFree(Entity, ( void** )&StructPtr, sYES );
- }
- else if((FreeMemory == sNO) && (StructPtr != NULL))
- {
- ret = sEntityFree(Entity, ( void** )&StructPtr, sNO );
- }
- return ret;
- }
Note: Here is the skeleton for sEntityFree()
Expand|Select|Wrap|Line Numbers
- int sEntityFree( sENTITY * Entity,
- void** StructPtr,
- sYORN FreeMemory )
StructPtr : void pointer to the pointer of the entity
data structure.
FreeMemory : Flag to indicate if the entity pointer
should be freed.
Please let me know. Thanks.