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 <mdr...@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);')
     else:
         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
-- 
1.7.0.4


Reply via email to