T
tfelb
Hi group!
There are many string functions out there and many use malloc/calloc
mechanisms /but/ they aren't freed before the function returns? When
it will be freed? Because if I use strdup many times the function
malloc's every time more space from the heap or is my thesis wrong?
I saw many implementations of strdup and they all are similar
char *strdup(char *s1)
{
char *newString;
newString = (char *)malloc(strlen(s1) + 1); /* I know casting
malloc isn't necessary
strcpy(newString,s1);
return newString; /* no freeing */
}
Thank you!
Tom F.
There are many string functions out there and many use malloc/calloc
mechanisms /but/ they aren't freed before the function returns? When
it will be freed? Because if I use strdup many times the function
malloc's every time more space from the heap or is my thesis wrong?
I saw many implementations of strdup and they all are similar
char *strdup(char *s1)
{
char *newString;
newString = (char *)malloc(strlen(s1) + 1); /* I know casting
malloc isn't necessary
strcpy(newString,s1);
return newString; /* no freeing */
}
Thank you!
Tom F.