]> Git Repo - qemu.git/commitdiff
qapi: Document that input visitor semantics are prone to leaks
authorEric Blake <[email protected]>
Thu, 30 Jul 2015 22:33:07 +0000 (16:33 -0600)
committerMarkus Armbruster <[email protected]>
Fri, 4 Sep 2015 13:47:14 +0000 (15:47 +0200)
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 <[email protected]>
Message-Id: <1438295587[email protected]>
Signed-off-by: Markus Armbruster <[email protected]>
scripts/qapi-visit.py
tests/test-qmp-input-visitor.c

index 73f136fc1d512c0aa5c21ffe0008928896961ec3..eec5f1f4c5881f6213337146d20d8a7e7a15cbc7 100644 (file)
@@ -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;
 
index b7a87ee35153fec4b15f6601433a9bfc7241be31..a5cfefae8bbce3b79f5e13dc2f80918f6e4450be 100644 (file)
@@ -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);
This page took 0.02736 seconds and 4 git commands to generate.