guillermoandres
Programmer
Hello everyone.
I have a little doubt about freeing allocated memory. I'm using this two functions.
gchar* status_code (gchar *status)
{
gchar* data = "";
sip_status ++;
while (*status != CR && *(status+1) != LF)
{
data = concatenar_char(data,status);
status ++;
}
return data;
}/*status_code*/
gchar * concatenar_char (gchar* str1, gchar* str2)
{
gchar *result;
if ( str2 != NULL )
{
result = (gchar *)malloc(strlen(str1) + sizeof(gchar) + 1);
if ( resultado != NULL )
{
strcpy(result, str1);
strncat(result, str2, 1);
}
}
return result;
}/*concatenar_char*/
In the second function I cant free result before return it. So where can I free the allocated memory (result) without getting an error from the compiler??
Is there a better way to do this?
Thanks in advance.
I have a little doubt about freeing allocated memory. I'm using this two functions.
gchar* status_code (gchar *status)
{
gchar* data = "";
sip_status ++;
while (*status != CR && *(status+1) != LF)
{
data = concatenar_char(data,status);
status ++;
}
return data;
}/*status_code*/
gchar * concatenar_char (gchar* str1, gchar* str2)
{
gchar *result;
if ( str2 != NULL )
{
result = (gchar *)malloc(strlen(str1) + sizeof(gchar) + 1);
if ( resultado != NULL )
{
strcpy(result, str1);
strncat(result, str2, 1);
}
}
return result;
}/*concatenar_char*/
In the second function I cant free result before return it. So where can I free the allocated memory (result) without getting an error from the compiler??
Is there a better way to do this?
Thanks in advance.