Hello. I'm using this function to concatenate two strings, and return the resulting string.
My question, Is this function leaking memory?Code:char * concatenate (char* str1, char* str2)
{
char *result;
if ( str2 != NULL )
{
result = malloc(strlen(str1) + strlen(str2) + 1);
if ( result != NULL )
{
strcpy(result, str1);
strcat(result, str2);
}
}
return result;
}
If it does, is there another way to do it? I just ran out of ideas.
Thanks!!!