On 03/07/2011 07:52 AM, Stefan Hajnoczi wrote:
On Mon, Mar 7, 2011 at 1:22 AM, Anthony Liguori<aligu...@us.ibm.com> wrote:
+static void qmp_chr_send_greeting(QmpSession *s)
+{
+ VersionInfo *info;
+ QObject *vers;
+ QObject *greeting;
+ QString *str;
+
+ info = qmp_query_version(NULL);
+ vers = qmp_marshal_type_VersionInfo(info);
+ qmp_free_version_info(info);
+
+ greeting = qobject_from_jsonf("{'QMP': {'version': %p, 'capabilities': []}
}",
+ vers);
+ str = qobject_to_json(greeting);
+ qobject_decref(greeting);
+
+ qemu_chr_write(s->chr, (void *)str->string, str->length);
+ qemu_chr_write(s->chr, (void *)"\n", 1);
+ QDECREF(str);
+}
Is vers leaked?
No, %p takes ownership of the object. qdict_put* also does FWIW.
The ownership semantics of QObject functions are very challenging. We
really need a concept of floating references to let stuff like this
continue to work without explicitly transferring ownership.
But really, a big part of this refactoring is isolating QObject so that
we can eventually replace it with GVariant so it may not be worth
worrying about.
Regards,
Anthony Liguori
Stefan