Here is a part of my code which is creating the error.
int check(int size, char *string)
{
if(condition)
{
char *tempStr = (char*)calloc(size, sizeof(char));
/*
some code here to put some string value to tempStr;
*/
res += check(size,tempStr);
free(tempStr);
}
}
I have read and understood that the invalid next error occurs when we try to free memory that isn't available or when we try to free memory more than once(assuming this is my case).
How to solve the above error? Is the above method correct way to free memory when in recursion?