I read from many question here in SO and some other articles regarding free() function in c that frees the memory of unused variables. In my case, I have the following code block.
char *injectStrAt(char *str, char *strToIn, int pos)
{
char *strC = malloc(strlen(str) + strlen(strToIn) + 1);
strncpy(strC, str, pos);
strC[pos] = '';
strcat(strC, strToIn);
strcat(strC, str + pos);
return strC;
}
The above function I use to inject a string block in to an array. I am using malloc
to create a new char*
. In the above case do I need to do free(strC)
? advice pls.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…