OSDN Git Service

hmp: Drop pointless allocation during qapi visit
authorEric Blake <eblake@redhat.com>
Fri, 29 Jan 2016 13:48:42 +0000 (06:48 -0700)
committerMarkus Armbruster <armbru@redhat.com>
Mon, 8 Feb 2016 16:29:55 +0000 (17:29 +0100)
The qapi visitor contract allows us to visit a virtual structure,
where we don't have any corresponding qapi struct.  Most such uses
pass NULL for @obj; but these two callers were passing a dummy
pointer, which then gets allocated to heap memory but then
immediately freed without use.  Clean this up to suppress unwanted
allocation, like we do elsewhere.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <1454075341-13658-7-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
hmp.c
vl.c

diff --git a/hmp.c b/hmp.c
index cb03a15..6071a0b 100644 (file)
--- a/hmp.c
+++ b/hmp.c
@@ -1657,7 +1657,6 @@ void hmp_object_add(Monitor *mon, const QDict *qdict)
     QemuOpts *opts;
     char *type = NULL;
     char *id = NULL;
-    void *dummy = NULL;
     OptsVisitor *ov;
     QDict *pdict;
 
@@ -1669,7 +1668,7 @@ void hmp_object_add(Monitor *mon, const QDict *qdict)
     ov = opts_visitor_new(opts);
     pdict = qdict_clone_shallow(qdict);
 
-    visit_start_struct(opts_get_visitor(ov), &dummy, NULL, NULL, 0, &err);
+    visit_start_struct(opts_get_visitor(ov), NULL, NULL, NULL, 0, &err);
     if (err) {
         goto out_clean;
     }
@@ -1701,7 +1700,6 @@ out_clean:
     qemu_opts_del(opts);
     g_free(id);
     g_free(type);
-    g_free(dummy);
 
 out:
     hmp_handle_error(mon, &err);
diff --git a/vl.c b/vl.c
index c581e39..db51ebd 100644 (file)
--- a/vl.c
+++ b/vl.c
@@ -2821,7 +2821,6 @@ static int object_create(void *opaque, QemuOpts *opts, Error **errp)
     Error *err = NULL;
     char *type = NULL;
     char *id = NULL;
-    void *dummy = NULL;
     OptsVisitor *ov;
     QDict *pdict;
     bool (*type_predicate)(const char *) = opaque;
@@ -2829,7 +2828,7 @@ static int object_create(void *opaque, QemuOpts *opts, Error **errp)
     ov = opts_visitor_new(opts);
     pdict = qemu_opts_to_qdict(opts, NULL);
 
-    visit_start_struct(opts_get_visitor(ov), &dummy, NULL, NULL, 0, &err);
+    visit_start_struct(opts_get_visitor(ov), NULL, NULL, NULL, 0, &err);
     if (err) {
         goto out;
     }
@@ -2864,7 +2863,6 @@ out:
     QDECREF(pdict);
     g_free(id);
     g_free(type);
-    g_free(dummy);
     if (err) {
         error_report_err(err);
         return -1;