From: Yin Kangkai <kangkai.yin@linux.intel.com>
To: linux-hotplug@vger.kernel.org
Subject: [PATCH 2/2 V2] fix some memory leaks.
Date: Mon, 02 Aug 2010 10:31:18 +0000 [thread overview]
Message-ID: <20100802103118.GM29131@kai-debian> (raw)
V2 for this patch, only the memory leaks fix. Thanks Kay.
From e550d7b79b7a8b1b4037d063e9630b3130005d80 Mon Sep 17 00:00:00 2001
From: Yin Kangkai <kangkai.yin@intel.com>
Date: Mon, 2 Aug 2010 18:25:32 +0800
Subject: [PATCH] Fix some memory leaks.
Signed-off-by: Yin Kangkai <kangkai.yin@intel.com>
---
udev/udev-rules.c | 15 ++++++++++++---
udev/udevd.c | 4 +++-
2 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/udev/udev-rules.c b/udev/udev-rules.c
index 6d32e73..4b81a50 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 95d4ad8..a7e4c8f 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;
--
1.6.5
next reply other threads:[~2010-08-02 10:31 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-08-02 10:31 Yin Kangkai [this message]
2010-08-02 10:36 ` [PATCH 2/2 V2] fix some memory leaks Kay Sievers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100802103118.GM29131@kai-debian \
--to=kangkai.yin@linux.intel.com \
--cc=linux-hotplug@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).