From: dunrong huang <riegamaths@gmail.com>
To: qemu-devel@nongnu.org
Cc: qemu-trivial@nongnu.org, Anthony Liguori <aliguori@us.ibm.com>,
dunrong huang <riegamaths@gmail.com>
Subject: [Qemu-devel] [PATCH] qdev: Fix memory leak
Date: Thu, 3 May 2012 16:34:42 +0800 [thread overview]
Message-ID: <1336034082-5288-1-git-send-email-riegamaths@gmail.com> (raw)
The str allocated in visit_type_str was not freed
Signed-off-by: dunrong huang <riegamaths@gmail.com>
---
hw/qdev-properties.c | 8 ++++++--
1 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index 98dd06a..8088699 100644
--- a/hw/qdev-properties.c
+++ b/hw/qdev-properties.c
@@ -726,7 +726,7 @@ static void set_mac(Object *obj, Visitor *v, void *opaque,
MACAddr *mac = qdev_get_prop_ptr(dev, prop);
Error *local_err = NULL;
int i, pos;
- char *str, *p;
+ char *str = NULL, *p;
if (dev->state != DEV_STATE_CREATED) {
error_set(errp, QERR_PERMISSION_DENIED);
@@ -753,10 +753,12 @@ static void set_mac(Object *obj, Visitor *v, void *opaque,
}
mac->a[i] = strtol(str+pos, &p, 16);
}
+ g_free(str);
return;
inval:
error_set_from_qdev_prop_error(errp, EINVAL, dev, prop, str);
+ g_free(str);
}
PropertyInfo qdev_prop_macaddr = {
@@ -825,7 +827,7 @@ static void set_pci_devfn(Object *obj, Visitor *v, void *opaque,
uint32_t *ptr = qdev_get_prop_ptr(dev, prop);
unsigned int slot, fn, n;
Error *local_err = NULL;
- char *str = (char *)"";
+ char *str = NULL;
if (dev->state != DEV_STATE_CREATED) {
error_set(errp, QERR_PERMISSION_DENIED);
@@ -847,10 +849,12 @@ static void set_pci_devfn(Object *obj, Visitor *v, void *opaque,
goto invalid;
}
*ptr = slot << 3 | fn;
+ g_free(str);
return;
invalid:
error_set_from_qdev_prop_error(errp, EINVAL, dev, prop, str);
+ g_free(str);
}
static int print_pci_devfn(DeviceState *dev, Property *prop, char *dest, size_t len)
--
1.7.8.4
next reply other threads:[~2012-05-03 8:35 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-03 8:34 dunrong huang [this message]
2012-05-14 19:36 ` [Qemu-devel] [PATCH] qdev: Fix memory leak Stefan Weil
2012-05-14 20:40 ` Michael Roth
2012-05-15 3:21 ` dunrong huang
2012-05-18 9:10 ` [Qemu-devel] [Qemu-trivial] " Stefan Hajnoczi
-- strict thread matches above, loose matches on Subject: below --
2012-05-03 7:02 [Qemu-devel] " dunrong huang
2012-05-03 8:33 ` dunrong huang
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=1336034082-5288-1-git-send-email-riegamaths@gmail.com \
--to=riegamaths@gmail.com \
--cc=aliguori@us.ibm.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-trivial@nongnu.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).