Patchwork [RFC,v2,06/17] qapi: fix memory leak for async marshalling code

mail settings
Submitter Michael Roth
Date April 18, 2011, 3:02 p.m.
Message ID <>
Download mbox | patch
Permalink /patch/91775/
State New
Headers show


Michael Roth - April 18, 2011, 3:02 p.m.
When generating the callback function for an async command, if we expect
a QString we copy it into a native char* type, then call the completion
function. We should free it after calling the completion function, since
the completion function will later copy it into a new QString before
adding it to the response object and then passing it on to the wire.

Signed-off-by: Michael Roth <>
--- |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)


diff --git a/ b/
index 4164692..3667ec5 100644
--- a/
+++ b/
@@ -349,6 +349,10 @@  static void qmp_%(c_name)s_cb(void *qmp__opaque, QObject *qmp__retval, Error *qm
         ret += cgen('    qmp__cb->cb(qmp__cb->opaque, qmp__err);')
         ret += cgen('    qmp__cb->cb(qmp__cb->opaque, qmp__native_retval, qmp__err);')
+    if retval != 'none' and qmp_type_should_free(retval):
+        ret += cgen('    %(free)s(qmp__native_retval);',
+                    free=qapi_free_func(retval))
     ret += cgen('}')
     return ret