mirror of
https://github.com/holub/mame
synced 2025-06-08 13:53:52 +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
|
// allocate memory
|
||||||
entry = malloc(sizeof(*entry));
|
entry = malloc(sizeof(*entry));
|
||||||
|
if (entry == NULL)
|
||||||
|
return 0;
|
||||||
|
|
||||||
string = malloc(strlen(data->string) + 1);
|
string = malloc(strlen(data->string) + 1);
|
||||||
|
if (string == NULL)
|
||||||
|
{
|
||||||
|
free(entry);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// if all allocations worked, make a new entry
|
// if all allocations worked, make a new entry
|
||||||
if (entry != NULL && string != NULL)
|
entry->next = idmaplist;
|
||||||
{
|
entry->name = string;
|
||||||
entry->next = idmaplist;
|
entry->id = data->id;
|
||||||
entry->name = string;
|
|
||||||
entry->id = data->id;
|
|
||||||
|
|
||||||
// copy the string and hook us into the list
|
// copy the string and hook us into the list
|
||||||
strcpy(string, data->string);
|
strcpy(string, data->string);
|
||||||
idmaplist = entry;
|
idmaplist = entry;
|
||||||
|
|
||||||
DEBUG_PRINTF((" id %d = '%s'\n", entry->id, entry->name));
|
DEBUG_PRINTF((" id %d = '%s'\n", entry->id, entry->name));
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user