* [Qemu-devel] [PATCH 0/2] fix two memory leaks in object_create()
@ 2014-08-15 10:13 Hu Tao
2014-08-15 10:13 ` [Qemu-devel] [PATCH 1/2] vl: free err Hu Tao
2014-08-15 10:14 ` [Qemu-devel] [PATCH 2/2] vl: call visit_end_struct() in the error path Hu Tao
0 siblings, 2 replies; 4+ messages in thread
From: Hu Tao @ 2014-08-15 10:13 UTC (permalink / raw)
To: qemu-devel
See each patch for the details.
Hu Tao (2):
vl: free err
vl: call visit_end_struct() in the error path
vl.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
--
1.9.3
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Qemu-devel] [PATCH 1/2] vl: free err
2014-08-15 10:13 [Qemu-devel] [PATCH 0/2] fix two memory leaks in object_create() Hu Tao
@ 2014-08-15 10:13 ` Hu Tao
2014-08-15 14:54 ` [Qemu-devel] [Qemu-trivial] " Michael Tokarev
2014-08-15 10:14 ` [Qemu-devel] [PATCH 2/2] vl: call visit_end_struct() in the error path Hu Tao
1 sibling, 1 reply; 4+ messages in thread
From: Hu Tao @ 2014-08-15 10:13 UTC (permalink / raw)
To: qemu-devel; +Cc: qemu-trivial
err is not freed after use, thus causing memory leak. This patch fixes
it.
Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
Cc: qemu-trivial@nongnu.org
---
vl.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/vl.c b/vl.c
index a8029d5..6011aff 100644
--- a/vl.c
+++ b/vl.c
@@ -2917,6 +2917,7 @@ out:
g_free(dummy);
if (err) {
qerror_report_err(err);
+ error_free(err);
return -1;
}
return 0;
--
1.9.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [Qemu-devel] [PATCH 2/2] vl: call visit_end_struct() in the error path
2014-08-15 10:13 [Qemu-devel] [PATCH 0/2] fix two memory leaks in object_create() Hu Tao
2014-08-15 10:13 ` [Qemu-devel] [PATCH 1/2] vl: free err Hu Tao
@ 2014-08-15 10:14 ` Hu Tao
1 sibling, 0 replies; 4+ messages in thread
From: Hu Tao @ 2014-08-15 10:14 UTC (permalink / raw)
To: qemu-devel
In the error path we should also call visit_end_struct(), otherwise we
will have memory leak.
Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
---
vl.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/vl.c b/vl.c
index 6011aff..738ef45 100644
--- a/vl.c
+++ b/vl.c
@@ -2876,6 +2876,7 @@ static int object_create(QemuOpts *opts, void *opaque)
char *type = NULL;
char *id = NULL;
void *dummy = NULL;
+ bool del_id_on_error = false;
OptsVisitor *ov;
QDict *pdict;
@@ -2890,21 +2891,21 @@ static int object_create(QemuOpts *opts, void *opaque)
qdict_del(pdict, "qom-type");
visit_type_str(opts_get_visitor(ov), &type, "qom-type", &err);
if (err) {
- goto out;
+ goto out_struct;
}
qdict_del(pdict, "id");
visit_type_str(opts_get_visitor(ov), &id, "id", &err);
if (err) {
- goto out;
+ goto out_struct;
}
object_add(type, id, pdict, opts_get_visitor(ov), &err);
- if (err) {
- goto out;
- }
+ del_id_on_error = true;
+
+out_struct:
visit_end_struct(opts_get_visitor(ov), &err);
- if (err) {
+ if (err && del_id_on_error) {
qmp_object_del(id, NULL);
}
--
1.9.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [Qemu-trivial] [PATCH 1/2] vl: free err
2014-08-15 10:13 ` [Qemu-devel] [PATCH 1/2] vl: free err Hu Tao
@ 2014-08-15 14:54 ` Michael Tokarev
0 siblings, 0 replies; 4+ messages in thread
From: Michael Tokarev @ 2014-08-15 14:54 UTC (permalink / raw)
To: Hu Tao, qemu-devel; +Cc: qemu-trivial
Applied to trivial, thank you!
/mjt
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-08-15 14:54 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-08-15 10:13 [Qemu-devel] [PATCH 0/2] fix two memory leaks in object_create() Hu Tao
2014-08-15 10:13 ` [Qemu-devel] [PATCH 1/2] vl: free err Hu Tao
2014-08-15 14:54 ` [Qemu-devel] [Qemu-trivial] " Michael Tokarev
2014-08-15 10:14 ` [Qemu-devel] [PATCH 2/2] vl: call visit_end_struct() in the error path Hu Tao
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).