[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 01/13] qapi: fix double free in qmp_output_visitor_c
From: |
Luiz Capitulino |
Subject: |
[Qemu-devel] [PATCH 01/13] qapi: fix double free in qmp_output_visitor_cleanup() |
Date: |
Tue, 27 Mar 2012 09:20:39 -0300 |
From: Laszlo Ersek <address@hidden>
Stack entries in QmpOutputVisitor are navigation links (weak references),
except the bottom (ie. least recently added) entry, which owns the root
QObject [1]. Make qmp_output_visitor_cleanup() drop the stack entries,
then release the QObject tree by the root.
Attempting to serialize an invalid enum inside a dictionary is an example
for triggering the double free.
[1] http://lists.nongnu.org/archive/html/qemu-devel/2012-03/msg03276.html
Signed-off-by: Laszlo Ersek <address@hidden>
Signed-off-by: Luiz Capitulino <address@hidden>
---
qapi/qmp-output-visitor.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/qapi/qmp-output-visitor.c b/qapi/qmp-output-visitor.c
index e0697b0..2bce9d5 100644
--- a/qapi/qmp-output-visitor.c
+++ b/qapi/qmp-output-visitor.c
@@ -199,14 +199,16 @@ void qmp_output_visitor_cleanup(QmpOutputVisitor *v)
{
QStackEntry *e, *tmp;
+ /* The bottom QStackEntry, if any, owns the root QObject. See the
+ * qmp_output_push_obj() invocations in qmp_output_add_obj(). */
+ QObject *root = QTAILQ_EMPTY(&v->stack) ? NULL : qmp_output_first(v);
+
QTAILQ_FOREACH_SAFE(e, &v->stack, node, tmp) {
QTAILQ_REMOVE(&v->stack, e, node);
- if (e->value) {
- qobject_decref(e->value);
- }
g_free(e);
}
+ qobject_decref(root);
g_free(v);
}
--
1.7.9.2.384.g4a92a
- [Qemu-devel] [PULL 00/13]: QMP queue, Luiz Capitulino, 2012/03/27
- [Qemu-devel] [PATCH 02/13] qapi: add struct-errors test case to test-qmp-output-visitor, Luiz Capitulino, 2012/03/27
- [Qemu-devel] [PATCH 01/13] qapi: fix double free in qmp_output_visitor_cleanup(),
Luiz Capitulino <=
- [Qemu-devel] [PATCH 03/13] qapi: add a test case for type errors, Luiz Capitulino, 2012/03/27
- [Qemu-devel] [PATCH 05/13] qapi: fix memory leak on error, Luiz Capitulino, 2012/03/27
- [Qemu-devel] [PATCH 06/13] qapi: shortcut visits on errors, Luiz Capitulino, 2012/03/27
- [Qemu-devel] [PATCH 08/13] qapi: untangle next_list, Luiz Capitulino, 2012/03/27
- [Qemu-devel] [PATCH 04/13] qapi: fail hard on stack imbalance, Luiz Capitulino, 2012/03/27
- [Qemu-devel] [PATCH 07/13] qapi: allow freeing partially-allocated objects, Luiz Capitulino, 2012/03/27
- [Qemu-devel] [PATCH 12/13] qmp: parse commands in strict mode, Luiz Capitulino, 2012/03/27
- [Qemu-devel] [PATCH 09/13] qapi: place outermost object on qiv stack, Luiz Capitulino, 2012/03/27
- [Qemu-devel] [PATCH 11/13] qmp: add and use q type specifier, Luiz Capitulino, 2012/03/27
- [Qemu-devel] [PATCH 13/13] qmp: document strict parsing, Luiz Capitulino, 2012/03/27