libudev: avoid leak during realloc failure
This commit is contained in:
parent
33b4055123
commit
cf2292f5ac
|
@ -185,18 +185,20 @@ struct udev_list_entry *udev_list_entry_add(struct udev_list *list, const char *
|
||||||
if (list->unique) {
|
if (list->unique) {
|
||||||
/* allocate or enlarge sorted array if needed */
|
/* allocate or enlarge sorted array if needed */
|
||||||
if (list->entries_cur >= list->entries_max) {
|
if (list->entries_cur >= list->entries_max) {
|
||||||
|
struct udev_list_entry **entries;
|
||||||
unsigned int add;
|
unsigned int add;
|
||||||
|
|
||||||
add = list->entries_max;
|
add = list->entries_max;
|
||||||
if (add < 1)
|
if (add < 1)
|
||||||
add = 64;
|
add = 64;
|
||||||
list->entries = realloc(list->entries, (list->entries_max + add) * sizeof(struct udev_list_entry *));
|
entries = realloc(list->entries, (list->entries_max + add) * sizeof(struct udev_list_entry *));
|
||||||
if (list->entries == NULL) {
|
if (entries == NULL) {
|
||||||
free(entry->name);
|
free(entry->name);
|
||||||
free(entry->value);
|
free(entry->value);
|
||||||
free(entry);
|
free(entry);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
list->entries = entries;
|
||||||
list->entries_max += add;
|
list->entries_max += add;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue