From: Christophe Jaillet [mailto:christophe.jaillet@wanadoo.fr]

Subject: Several patchlets

    ledutil.diff
- checking if memory is allocated before using it is good, freeing what
has
been allocated in the error path is better
This commit is contained in:
Aaron Giles 2008-09-11 15:40:54 +00:00
parent 0b3ae8f72d
commit f67c8732b2

View File

@ -382,21 +382,26 @@ static LRESULT handle_copydata(WPARAM wparam, LPARAM lparam)
// allocate memory
entry = malloc(sizeof(*entry));
if (entry == NULL)
return 0;
string = malloc(strlen(data->string) + 1);
if (string == NULL)
{
free(entry);
return 0;
}
// if all allocations worked, make a new entry
if (entry != NULL && string != NULL)
{
entry->next = idmaplist;
entry->name = string;
entry->id = data->id;
entry->next = idmaplist;
entry->name = string;
entry->id = data->id;
// copy the string and hook us into the list
strcpy(string, data->string);
idmaplist = entry;
// copy the string and hook us into the list
strcpy(string, data->string);
idmaplist = entry;
DEBUG_PRINTF((" id %d = '%s'\n", entry->id, entry->name));
}
DEBUG_PRINTF((" id %d = '%s'\n", entry->id, entry->name));
return 0;
}