diff options
| author | 2008-09-11 15:40:54 +0000 | |
|---|---|---|
| committer | 2008-09-11 15:40:54 +0000 | |
| commit | f67c8732b288cd5bbf7b8c80134e979697d57dfc (patch) | |
| tree | 7453efeb883a8b878c08091516c00d2f1386e4fb | |
| parent | 0b3ae8f72dade6daeba7ceb30a44cd4756ea1b53 (diff) | |
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
| -rw-r--r-- | src/osd/windows/ledutil.c | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/src/osd/windows/ledutil.c b/src/osd/windows/ledutil.c index f201f143bfa..285361fd106 100644 --- a/src/osd/windows/ledutil.c +++ b/src/osd/windows/ledutil.c @@ -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; } |
