Hello,
I need to write a function such that it frees all the pointers that I allocate.My code looks like this:
Code:
int someFunction()
{
//Allocating pointers.
szTemp1 = calloc(10, sizeof(char));
stTemp2 = calloc(10 , sizeof(char));
stTemp3 = calloc (10 , sizeof(char));
//Logic goes here
if ( something bad happened)
{
//free all pointers
free(szTemp1 );
free(szTemp2 );
free(szTemp3 );
return FAIL;
}
if( something else goes wrong)
{
//free all pointers
free(szTemp1 );
free(szTemp2 );
free(szTemp3 );
return FAIL;
}
//Finally in the end:
//free all pointers
free(szTemp1 );
free(szTemp2 );
free(szTemp3 );
return SUCCESS;
}
Here , instead of repeating the same lines to free the pointers everytime in the code, I would like to call a function which releases all pointers. How would i do it? I would not want to use the goto statement to achieve the same.
Please help.