fix OOM handling in hash routines

* src/util/hash.c: virHashAddEntry and virHashUpdateEntry were missing NULL
  checks on strdup
* AUTHORS: add Christophe Fergeau
This commit is contained in:
Christophe Fergeau 2011-02-14 13:36:06 +08:00 committed by Daniel Veillard
parent eebf4dc343
commit 9190f0b0a0
2 changed files with 17 additions and 3 deletions

View File

@ -154,6 +154,7 @@ Patches have also been contributed by:
Zdenek Styblik <stybla@turnovfree.net> Zdenek Styblik <stybla@turnovfree.net>
Gui Jianfeng <guijianfeng@cn.fujitsu.com> Gui Jianfeng <guijianfeng@cn.fujitsu.com>
Michal Novotny <minovotn@redhat.com> Michal Novotny <minovotn@redhat.com>
Christophe Fergeau <teuf@gnome.org>
[....send patches to get your name here....] [....send patches to get your name here....]

View File

@ -253,6 +253,7 @@ virHashAddEntry(virHashTablePtr table, const char *name, void *userdata)
unsigned long key, len = 0; unsigned long key, len = 0;
virHashEntryPtr entry; virHashEntryPtr entry;
virHashEntryPtr insert; virHashEntryPtr insert;
char *new_name;
if ((table == NULL) || (name == NULL)) if ((table == NULL) || (name == NULL))
return (-1); return (-1);
@ -281,12 +282,17 @@ virHashAddEntry(virHashTablePtr table, const char *name, void *userdata)
return (-1); return (-1);
} }
entry->name = strdup(name); new_name = strdup(name);
if (new_name == NULL) {
if (insert != NULL)
VIR_FREE(entry);
return (-1);
}
entry->name = new_name;
entry->payload = userdata; entry->payload = userdata;
entry->next = NULL; entry->next = NULL;
entry->valid = 1; entry->valid = 1;
if (insert != NULL) if (insert != NULL)
insert->next = entry; insert->next = entry;
@ -318,6 +324,7 @@ virHashUpdateEntry(virHashTablePtr table, const char *name,
unsigned long key; unsigned long key;
virHashEntryPtr entry; virHashEntryPtr entry;
virHashEntryPtr insert; virHashEntryPtr insert;
char *new_name;
if ((table == NULL) || name == NULL) if ((table == NULL) || name == NULL)
return (-1); return (-1);
@ -353,7 +360,13 @@ virHashUpdateEntry(virHashTablePtr table, const char *name,
return (-1); return (-1);
} }
entry->name = strdup(name); new_name= strdup(name);
if (new_name == NULL) {
if (insert != NULL)
VIR_FREE(entry);
return (-1);
}
entry->name = new_name;
entry->payload = userdata; entry->payload = userdata;
entry->next = NULL; entry->next = NULL;
entry->valid = 1; entry->valid = 1;