[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH V26 05/32] QemuOpts: change opt->name|str from (cons
From: |
Chunyan Liu |
Subject: |
[Qemu-devel] [PATCH V26 05/32] QemuOpts: change opt->name|str from (const char *) to (char *) |
Date: |
Tue, 29 Apr 2014 17:08:14 +0800 |
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 <address@hidden>
Signed-off-by: Chunyan Liu <address@hidden>
---
include/qemu/option_int.h | 4 ++--
qapi/opts-visitor.c | 10 +++++++---
util/qemu-option.c | 4 ++--
3 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/include/qemu/option_int.h b/include/qemu/option_int.h
index 8212fa4..6432c1a 100644
--- a/include/qemu/option_int.h
+++ b/include/qemu/option_int.h
@@ -30,8 +30,8 @@
#include "qemu/error-report.h"
struct QemuOpt {
- const char *name;
- const char *str;
+ char *name;
+ char *str;
const QemuOptDesc *desc;
union {
diff --git a/qapi/opts-visitor.c b/qapi/opts-visitor.c
index 5d830a2..7a64f4e 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;
}
diff --git a/util/qemu-option.c b/util/qemu-option.c
index 2be6995..69cdf3f 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -664,8 +664,8 @@ static void qemu_opt_parse(QemuOpt *opt, Error **errp)
static void qemu_opt_del(QemuOpt *opt)
{
QTAILQ_REMOVE(&opt->opts->head, opt, next);
- g_free((/* !const */ char*)opt->name);
- g_free((/* !const */ char*)opt->str);
+ g_free(opt->name);
+ g_free(opt->str);
g_free(opt);
}
--
1.8.4.5
- [Qemu-devel] [PATCH V26 01/32] QemuOpts: move find_desc_by_name ahead for later calling, (continued)
- [Qemu-devel] [PATCH V26 01/32] QemuOpts: move find_desc_by_name ahead for later calling, Chunyan Liu, 2014/04/29
- [Qemu-devel] [PATCH V26 04/32] qapi: output def_value_str when query command line options, Chunyan Liu, 2014/04/29
- [Qemu-devel] [PATCH V26 02/32] QemuOpts: add def_value_str to QemuOptDesc, Chunyan Liu, 2014/04/29
- [Qemu-devel] [PATCH V26 03/32] QemuOpts: repurpose qemu_opts_print to replace print_option_parameters, Chunyan Liu, 2014/04/29
- [Qemu-devel] [PATCH V26 29/32] vmdk.c: replace QEMUOptionParameter with QemuOpts, Chunyan Liu, 2014/04/29
- [Qemu-devel] [PATCH V26 17/32] nfs.c: replace QEMUOptionParameter with QemuOpts, Chunyan Liu, 2014/04/29
- [Qemu-devel] [PATCH V26 22/32] raw-win32.c: replace QEMUOptionParameter with QemuOpts, Chunyan Liu, 2014/04/29
- [Qemu-devel] [PATCH V26 11/32] QemuOpts: check NULL input for qemu_opts_del, Chunyan Liu, 2014/04/29
- [Qemu-devel] [PATCH V26 28/32] vhdx.c: replace QEMUOptionParameter with QemuOpts, Chunyan Liu, 2014/04/29
- [Qemu-devel] [PATCH V26 16/32] iscsi.c: replace QEMUOptionParameter with QemuOpts, Chunyan Liu, 2014/04/29
- [Qemu-devel] [PATCH V26 05/32] QemuOpts: change opt->name|str from (const char *) to (char *),
Chunyan Liu <=
- [Qemu-devel] [PATCH V26 27/32] vdi.c: replace QEMUOptionParameter with QemuOpts, Chunyan Liu, 2014/04/29
- [Qemu-devel] [PATCH V26 31/32] cleanup QEMUOptionParameter, Chunyan Liu, 2014/04/29