[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 14/33] qapi: Document that input visitor semantics ar
From: |
Markus Armbruster |
Subject: |
[Qemu-devel] [PULL 14/33] qapi: Document that input visitor semantics are prone to leaks |
Date: |
Fri, 4 Sep 2015 16:21:21 +0200 |
From: Eric Blake <address@hidden>
Most functions that can return a pointer or set an Error ** value
are decent enough to guarantee a NULL return when reporting an error.
Not so with our generated qapi visitor functions. If the caller
is not careful to clean up partially-allocated objects on error,
then the caller suffers a memory leak.
Properly fixing it is probably complex enough to save for a later
day, so merely document it for now.
Signed-off-by: Eric Blake <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Markus Armbruster <address@hidden>
---
scripts/qapi-visit.py | 4 ++++
tests/test-qmp-input-visitor.c | 2 ++
2 files changed, 6 insertions(+)
diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py
index 73f136f..eec5f1f 100644
--- a/scripts/qapi-visit.py
+++ b/scripts/qapi-visit.py
@@ -115,6 +115,10 @@ out:
def generate_visit_struct_body(name):
+ # FIXME: if *obj is NULL on entry, and visit_start_struct() assigns to
+ # *obj, but then visit_type_FOO_fields() fails, we should clean up *obj
+ # rather than leaving it non-NULL. As currently written, the caller must
+ # call qapi_free_FOO() to avoid a memory leak of the partial FOO.
ret = mcgen('''
Error *err = NULL;
diff --git a/tests/test-qmp-input-visitor.c b/tests/test-qmp-input-visitor.c
index b7a87ee..a5cfefa 100644
--- a/tests/test-qmp-input-visitor.c
+++ b/tests/test-qmp-input-visitor.c
@@ -636,6 +636,8 @@ static void test_visitor_in_errors(TestInputVisitorData
*data,
visit_type_TestStruct(v, &p, NULL, &err);
g_assert(err);
+ /* FIXME - a failed parse should not leave a partially-allocated p
+ * for us to clean up; this could cause callers to leak memory. */
g_assert(p->string == NULL);
error_free(err);
--
2.4.3
- [Qemu-devel] [PULL 00/33] qapi: Another round of fixes and cleanups, Markus Armbruster, 2015/09/04
- [Qemu-devel] [PULL 04/33] qapi-event: Clean up how name of enum QAPIEvent is made, Markus Armbruster, 2015/09/04
- [Qemu-devel] [PULL 05/33] qapi: Reject -p arguments that break qapi-event.py, Markus Armbruster, 2015/09/04
- [Qemu-devel] [PULL 03/33] qapi: Simplify guardname(), Markus Armbruster, 2015/09/04
- [Qemu-devel] [PULL 01/33] qapi: Clarify docs on including the same file multiple times, Markus Armbruster, 2015/09/04
- [Qemu-devel] [PULL 11/33] qapi-visit: Fix two name arguments passed to visitors, Markus Armbruster, 2015/09/04
- [Qemu-devel] [PULL 07/33] qapi: Fix generated code when flat union has member 'kind', Markus Armbruster, 2015/09/04
- [Qemu-devel] [PULL 14/33] qapi: Document that input visitor semantics are prone to leaks,
Markus Armbruster <=
- [Qemu-devel] [PULL 13/33] tests/qapi-schema: Document events with base don't work, Markus Armbruster, 2015/09/04
- [Qemu-devel] [PULL 15/33] qapi: Document shortcoming with union 'data' branch, Markus Armbruster, 2015/09/04
- [Qemu-devel] [PULL 06/33] qapi: Drop unused and useless parameters and variables, Markus Armbruster, 2015/09/04
- [Qemu-devel] [PULL 23/33] qapi-commands: Inline gen_marshal_output_call(), Markus Armbruster, 2015/09/04
- [Qemu-devel] [PULL 27/33] qapi: Drop one of two "simple union must not have base" checks, Markus Armbruster, 2015/09/04
- [Qemu-devel] [PULL 25/33] qapi-commands: Drop useless initialization, Markus Armbruster, 2015/09/04
- [Qemu-devel] [PULL 02/33] qapi: Clean up cgen() and mcgen(), Markus Armbruster, 2015/09/04
- [Qemu-devel] [PULL 22/33] qapi-commands: Fix gen_err_check(e) for e and e != 'local_err', Markus Armbruster, 2015/09/04