Moved to realloc instead of always allocating new memory.

This commit is contained in:
Markus Makela
2015-08-28 09:48:38 +03:00
parent de643df067
commit 50d1675c7b

View File

@ -175,15 +175,14 @@ CONFIG_PARAMETER *param, *p1;
if (!strcmp(p1->name, name))
{
char* tmp;
int paramlen = strlen(p1->value) + strlen(value) + 2;
if((tmp = malloc(sizeof(char) * (strlen(p1->value) + strlen(value) + 2))) == NULL)
if((tmp = realloc(p1->value,sizeof(char) * (paramlen))) == NULL)
{
skygw_log_write(LE,"[%s] Error: Memory allocation failed.",__FUNCTION__);
return 0;
}
strcpy(tmp,p1->value);
strcat(tmp,value);
free(p1->value);
p1->value = tmp;
return 1;
}