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

Message ID 1303138953-1334-7-git-send-email-mdroth@linux.vnet.ibm.com
State New
Headers show

Commit Message

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 <mdroth@linux.vnet.ibm.com>
 qmp-gen.py |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)


diff --git a/qmp-gen.py b/qmp-gen.py
index 4164692..3667ec5 100644
--- a/qmp-gen.py
+++ b/qmp-gen.py
@@ -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