chiark / gitweb /
udev: fix two trivial memleaks in error path
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 18 Jul 2013 23:36:55 +0000 (19:36 -0400)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 19 Jul 2013 13:57:04 +0000 (09:57 -0400)
Based-on-a-patch-by: Ian Stakenvicius <axs@gentoo.org>
src/udev/collect/collect.c
src/udev/udevadm-hwdb.c

index f95ee23..1346f27 100644 (file)
@@ -442,19 +442,19 @@ int main(int argc, char **argv)
 
                         if (debug)
                                 fprintf(stderr, "ID %s: not in database\n", argv[i]);
-                        him = malloc(sizeof (struct _mate));
+                        him = new(struct _mate, 1);
                         if (!him) {
                                 ret = ENOMEM;
                                 goto out;
                         }
 
-                        him->name = malloc(strlen(argv[i]) + 1);
+                        him->name = strdup(argv[i]);
                         if (!him->name) {
+                                free(him);
                                 ret = ENOMEM;
                                 goto out;
                         }
 
-                        strcpy(him->name, argv[i]);
                         him->state = STATE_NONE;
                         udev_list_node_append(&him->node, &bunch);
                 } else {
index 4136b17..d9dc73b 100644 (file)
@@ -303,8 +303,10 @@ static int64_t trie_store_nodes(struct trie_f *trie, struct trie_node *node) {
                 int64_t child_off;
 
                 child_off = trie_store_nodes(trie, node->children[i].child);
-                if (child_off < 0)
+                if (child_off < 0) {
+                        free(children);
                         return child_off;
+                }
                 children[i].c = node->children[i].c;
                 children[i].child_off = htole64(child_off);
         }