diff options
author | Chunyan Liu <cyliu@suse.com> | 2014-06-05 17:20:44 +0800 |
---|---|---|
committer | Stefan Hajnoczi <stefanha@redhat.com> | 2014-06-16 17:23:20 +0800 |
commit | dc8622f2bf9174cd42932ad86bcc98c6f7c98832 (patch) | |
tree | 14e4d35b5b4bd428a0c0206d8200c31314f5fe7e /qapi/opts-visitor.c | |
parent | e36af94f868fe5b897c4903126e11fdf25fa4739 (diff) | |
download | qemu-dc8622f2bf9174cd42932ad86bcc98c6f7c98832.zip qemu-dc8622f2bf9174cd42932ad86bcc98c6f7c98832.tar.gz qemu-dc8622f2bf9174cd42932ad86bcc98c6f7c98832.tar.bz2 |
QemuOpts: change opt->name|str from (const char *) to (char *)
qemu_opt_del() already assumes that all QemuOpt instances contain
malloc'd name and value; but it had to cast away const because
opts_start_struct() was doing its own thing and using static storage
instead. By using the correct type and malloced strings everywhere, the
usage of this struct becomes clearer.
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Leandro Dorileo <l@dorileo.org>
Signed-off-by: Chunyan Liu <cyliu@suse.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Diffstat (limited to 'qapi/opts-visitor.c')
-rw-r--r-- | qapi/opts-visitor.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/qapi/opts-visitor.c b/qapi/opts-visitor.c index 16382e7..f2ad6d7 100644 --- a/qapi/opts-visitor.c +++ b/qapi/opts-visitor.c @@ -143,8 +143,8 @@ opts_start_struct(Visitor *v, void **obj, const char *kind, if (ov->opts_root->id != NULL) { ov->fake_id_opt = g_malloc0(sizeof *ov->fake_id_opt); - ov->fake_id_opt->name = "id"; - ov->fake_id_opt->str = ov->opts_root->id; + ov->fake_id_opt->name = g_strdup("id"); + ov->fake_id_opt->str = g_strdup(ov->opts_root->id); opts_visitor_insert(ov->unprocessed_opts, ov->fake_id_opt); } } @@ -177,7 +177,11 @@ opts_end_struct(Visitor *v, Error **errp) } g_hash_table_destroy(ov->unprocessed_opts); ov->unprocessed_opts = NULL; - g_free(ov->fake_id_opt); + if (ov->fake_id_opt) { + g_free(ov->fake_id_opt->name); + g_free(ov->fake_id_opt->str); + g_free(ov->fake_id_opt); + } ov->fake_id_opt = NULL; } |