Quote Originally Posted by forstudy3 View Post
GetGroupStatus() is called in for loop from Main.So when i = 0 it works fine , after that when I tries to free the memory throws an error message.Would it be good practise to set again to NULL after freeing.

if (cTemp != NULL)
free(cTemp);


*cTemp = NULL
It should be cTemp = NULL; cause cTemp is the pointer and not *cTemp.

Setting to NULL after free won't solve the problem if the cTemp is a local variable and you would return after that. But it is not useless cause the old pointer value isn't valid after free, hence it is less error-prone for future enhancements to initialize the invalid pointer variable again.

If the cTemp is a shared variable (either member variable or global variable) it is essential that you initialize it to NULL after free.

Looking at the code you posted I would assume that you already freed the pointer somewhere else. You can avoid such mistakes by always freeing pointers on the same calling level where you made the malloc or strdup. So if you passed a pointer to a function never free it in the function called but always in the calling function.