[systemd-devel] [PATCH] libudev: avoid leak during realloc failure

Mauro Dreissig mukadr at gmail.com
Sun Nov 11 16:07:51 PST 2012


---
 src/libudev/libudev-list.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/libudev/libudev-list.c b/src/libudev/libudev-list.c
index 5d09b5d..4cec3b8 100644
--- a/src/libudev/libudev-list.c
+++ b/src/libudev/libudev-list.c
@@ -177,18 +177,20 @@ struct udev_list_entry *udev_list_entry_add(struct udev_list *list, const char *
         if (list->unique) {
                 /* allocate or enlarge sorted array if needed */
                 if (list->entries_cur >= list->entries_max) {
+                        struct udev_list_entry **entries;
                         unsigned int add;
 
                         add = list->entries_max;
                         if (add < 1)
                                 add = 64;
-                        list->entries = realloc(list->entries, (list->entries_max + add) * sizeof(struct udev_list_entry *));
-                        if (list->entries == NULL) {
+                        entries = realloc(list->entries, (list->entries_max + add) * sizeof(struct udev_list_entry *));
+                        if (entries == NULL) {
                                 free(entry->name);
                                 free(entry->value);
                                 free(entry);
                                 return NULL;
                         }
+                        list->entries = entries;
                         list->entries_max += add;
                 }

--
1.7.11.7


More information about the systemd-devel mailing list