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>
This commit is contained in:
Chunyan Liu 2014-06-05 17:20:44 +08:00 committed by Stefan Hajnoczi
parent e36af94f86
commit dc8622f2bf
3 changed files with 11 additions and 7 deletions

View File

@ -30,8 +30,8 @@
#include "qemu/error-report.h" #include "qemu/error-report.h"
struct QemuOpt { struct QemuOpt {
const char *name; char *name;
const char *str; char *str;
const QemuOptDesc *desc; const QemuOptDesc *desc;
union { union {

View File

@ -143,8 +143,8 @@ opts_start_struct(Visitor *v, void **obj, const char *kind,
if (ov->opts_root->id != NULL) { if (ov->opts_root->id != NULL) {
ov->fake_id_opt = g_malloc0(sizeof *ov->fake_id_opt); ov->fake_id_opt = g_malloc0(sizeof *ov->fake_id_opt);
ov->fake_id_opt->name = "id"; ov->fake_id_opt->name = g_strdup("id");
ov->fake_id_opt->str = ov->opts_root->id; ov->fake_id_opt->str = g_strdup(ov->opts_root->id);
opts_visitor_insert(ov->unprocessed_opts, ov->fake_id_opt); 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); g_hash_table_destroy(ov->unprocessed_opts);
ov->unprocessed_opts = NULL; ov->unprocessed_opts = NULL;
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); g_free(ov->fake_id_opt);
}
ov->fake_id_opt = NULL; ov->fake_id_opt = NULL;
} }

View File

@ -664,8 +664,8 @@ static void qemu_opt_parse(QemuOpt *opt, Error **errp)
static void qemu_opt_del(QemuOpt *opt) static void qemu_opt_del(QemuOpt *opt)
{ {
QTAILQ_REMOVE(&opt->opts->head, opt, next); QTAILQ_REMOVE(&opt->opts->head, opt, next);
g_free((/* !const */ char*)opt->name); g_free(opt->name);
g_free((/* !const */ char*)opt->str); g_free(opt->str);
g_free(opt); g_free(opt);
} }