[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v28 33/33] QemuOpts: cleanup tmp 'allocated' member
From: |
Chunyan Liu |
Subject: |
[Qemu-devel] [PATCH v28 33/33] QemuOpts: cleanup tmp 'allocated' member from QemuOptsList |
Date: |
Thu, 5 Jun 2014 17:21:12 +0800 |
Now only qemu_opts_append uses 'allocated' to indicate free memory.
For this function only, we can also let result list's (const char *)
members point to input list's members, only if the input list has
longer lifetime than result list. In current code, that is true.
So, we can remove the 'allocated' member from QemuOptsList definition
to keep code clean.
Signed-off-by: Chunyan Liu <address@hidden>
---
include/qemu/option.h | 6 ------
util/qemu-option.c | 27 +++------------------------
2 files changed, 3 insertions(+), 30 deletions(-)
diff --git a/include/qemu/option.h b/include/qemu/option.h
index 921eccd..59bea75 100644
--- a/include/qemu/option.h
+++ b/include/qemu/option.h
@@ -63,12 +63,6 @@ typedef struct QemuOptDesc {
} QemuOptDesc;
struct QemuOptsList {
- /* FIXME: Temp used for QEMUOptionParamter->QemuOpts conversion to
- * indicate the need to free memory. Will remove after all drivers
- * switch to QemuOpts.
- */
- bool allocated;
-
const char *name;
const char *implied_opt_name;
bool merge_lists; /* Merge multiple uses of option into a single list? */
diff --git a/util/qemu-option.c b/util/qemu-option.c
index 8ac8111..836055a 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -1077,26 +1077,13 @@ static size_t count_opts_list(QemuOptsList *list)
void qemu_opts_free(QemuOptsList *list)
{
- /* List members point to new malloced space and need to be freed.
- * FIXME:
- * Introduced for QEMUOptionParamter->QemuOpts conversion.
- * Will remove after all drivers switch to QemuOpts.
- */
- if (list && list->allocated) {
- QemuOptDesc *desc = list->desc;
- while (desc && desc->name) {
- g_free((char *)desc->name);
- g_free((char *)desc->help);
- g_free((char *)desc->def_value_str);
- desc++;
- }
- }
-
g_free(list);
}
/* Realloc dst option list and append options from an option list (list)
* to it. dst could be NULL or a malloced list.
+ * The lifetime of dst must be shorter than the input list because the
+ * QemuOptDesc->name, ->help, and ->def_value_str strings are shared.
*/
QemuOptsList *qemu_opts_append(QemuOptsList *dst,
QemuOptsList *list)
@@ -1125,24 +1112,16 @@ QemuOptsList *qemu_opts_append(QemuOptsList *dst,
dst->name = NULL;
dst->implied_opt_name = NULL;
QTAILQ_INIT(&dst->head);
- dst->allocated = true;
dst->merge_lists = false;
}
dst->desc[num_dst_opts].name = NULL;
- /* (const char *) members of result dst are malloced, need free. */
- assert(dst->allocated);
/* append list->desc to dst->desc */
if (list) {
desc = list->desc;
while (desc && desc->name) {
if (find_desc_by_name(dst->desc, desc->name) == NULL) {
- dst->desc[num_dst_opts].name = g_strdup(desc->name);
- dst->desc[num_dst_opts].type = desc->type;
- dst->desc[num_dst_opts].help = g_strdup(desc->help);
- dst->desc[num_dst_opts].def_value_str =
- g_strdup(desc->def_value_str);
- num_dst_opts++;
+ dst->desc[num_dst_opts++] = *desc;
dst->desc[num_dst_opts].name = NULL;
}
desc++;
--
1.7.12.4
- [Qemu-devel] [PATCH v28 20/33] qcow2.c: replace QEMUOptionParameter with QemuOpts, (continued)
- [Qemu-devel] [PATCH v28 20/33] qcow2.c: replace QEMUOptionParameter with QemuOpts, Chunyan Liu, 2014/06/05
- [Qemu-devel] [PATCH v28 21/33] qed.c: replace QEMUOptionParameter with QemuOpts, Chunyan Liu, 2014/06/05
- [Qemu-devel] [PATCH v28 24/33] raw_bsd.c: replace QEMUOptionParameter with QemuOpts, Chunyan Liu, 2014/06/05
- [Qemu-devel] [PATCH v28 23/33] raw-win32.c: replace QEMUOptionParameter with QemuOpts, Chunyan Liu, 2014/06/05
- [Qemu-devel] [PATCH v28 25/33] rbd.c: replace QEMUOptionParameter with QemuOpts, Chunyan Liu, 2014/06/05
- [Qemu-devel] [PATCH v28 26/33] sheepdog.c: replace QEMUOptionParameter with QemuOpts, Chunyan Liu, 2014/06/05
- [Qemu-devel] [PATCH v28 27/33] ssh.c: replace QEMUOptionParameter with QemuOpts, Chunyan Liu, 2014/06/05
- [Qemu-devel] [PATCH v28 28/33] vdi.c: replace QEMUOptionParameter with QemuOpts, Chunyan Liu, 2014/06/05
- [Qemu-devel] [PATCH v28 29/33] vhdx.c: replace QEMUOptionParameter with QemuOpts, Chunyan Liu, 2014/06/05
- [Qemu-devel] [PATCH v28 31/33] vpc.c: replace QEMUOptionParameter with QemuOpts, Chunyan Liu, 2014/06/05
- [Qemu-devel] [PATCH v28 33/33] QemuOpts: cleanup tmp 'allocated' member from QemuOptsList,
Chunyan Liu <=
- [Qemu-devel] [PATCH v28 32/33] cleanup QEMUOptionParameter, Chunyan Liu, 2014/06/05
- [Qemu-devel] [PATCH v28 30/33] vmdk.c: replace QEMUOptionParameter with QemuOpts, Chunyan Liu, 2014/06/05
- Re: [Qemu-devel] [PATCH v28 00/33] replace QEMUOptionParameter with QemuOpts, Stefan Hajnoczi, 2014/06/05
- Re: [Qemu-devel] [PATCH v28 00/33] replace QEMUOptionParameter with QemuOpts, Stefan Hajnoczi, 2014/06/09
- Re: [Qemu-devel] [PATCH v28 00/33] replace QEMUOptionParameter with QemuOpts, Stefan Hajnoczi, 2014/06/12
- Re: [Qemu-devel] [PATCH v28 00/33] replace QEMUOptionParameter with QemuOpts, Peter Lieven, 2014/06/23