mirror of
https://github.com/holub/mame
synced 2025-04-20 23:42:22 +03:00
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:
parent
0b3ae8f72d
commit
f67c8732b2
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user