summaryrefslogtreecommitdiff
path: root/udev
diff options
context:
space:
mode:
authorYin Kangkai <kangkai.yin@linux.intel.com>2010-08-02 18:31:18 +0800
committerKay Sievers <kay.sievers@vrfy.org>2010-08-02 12:37:55 +0200
commit1851332c08e3f70ee172bbe5b153789da5df2df5 (patch)
tree378ebd2d9b1e52435375ddf54e1abeb24ee18405 /udev
parent5047f82de4d3b973281993516441a35cebcf1294 (diff)
udevd: fix some memory leaks in error path
Signed-off-by: Yin Kangkai <kangkai.yin@intel.com>
Diffstat (limited to 'udev')
-rw-r--r--udev/udev-rules.c15
-rw-r--r--udev/udevd.c4
2 files changed, 15 insertions, 4 deletions
diff --git a/udev/udev-rules.c b/udev/udev-rules.c
index 6d32e73017..4b81a50a8e 100644
--- a/udev/udev-rules.c
+++ b/udev/udev-rules.c
@@ -1761,13 +1761,18 @@ struct udev_rules *udev_rules_new(struct udev *udev, int resolve_names)
/* init token array and string buffer */
rules->tokens = malloc(PREALLOC_TOKEN * sizeof(struct token));
- if (rules->tokens == NULL)
+ if (rules->tokens == NULL) {
+ free(rules);
return NULL;
+ }
rules->token_max = PREALLOC_TOKEN;
rules->buf = malloc(PREALLOC_STRBUF);
- if (rules->buf == NULL)
+ if (rules->buf == NULL) {
+ free(rules->tokens);
+ free(rules);
return NULL;
+ }
rules->buf_max = PREALLOC_STRBUF;
/* offset 0 is always '\0' */
rules->buf[0] = '\0';
@@ -1776,8 +1781,12 @@ struct udev_rules *udev_rules_new(struct udev *udev, int resolve_names)
rules->token_max * sizeof(struct token), rules->token_max, sizeof(struct token), rules->buf_max);
rules->trie_nodes = malloc(PREALLOC_TRIE * sizeof(struct trie_node));
- if (rules->trie_nodes == NULL)
+ if (rules->trie_nodes == NULL) {
+ free(rules->buf);
+ free(rules->tokens);
+ free(rules);
return NULL;
+ }
rules->trie_nodes_max = PREALLOC_TRIE;
/* offset 0 is the trie root, with an empty string */
memset(rules->trie_nodes, 0x00, sizeof(struct trie_node));
diff --git a/udev/udevd.c b/udev/udevd.c
index 873634fe45..fbc237143c 100644
--- a/udev/udevd.c
+++ b/udev/udevd.c
@@ -227,8 +227,10 @@ static void worker_new(struct event *event)
udev_monitor_enable_receiving(worker_monitor);
worker = calloc(1, sizeof(struct worker));
- if (worker == NULL)
+ if (worker == NULL) {
+ udev_monitor_unref(worker_monitor);
return;
+ }
/* worker + event reference */
worker->refcount = 2;
worker->udev = event->udev;