Patchwork [2/3] blkdebug: Free QemuOpts after having read the config

login
register
mail settings
Submitter Markus Armbruster
Date July 1, 2010, 6:47 a.m.
Message ID <m3zkyblmvm.fsf@blackfin.pond.sub.org>
Download mbox | patch
Permalink /patch/57475/
State New
Headers show

Comments

Markus Armbruster - July 1, 2010, 6:47 a.m.
Kevin Wolf <kwolf@redhat.com> writes:

> Forgetting to free them means that the next instance inherits all rules and
> gets its own rules only additionally.

I also found a use for freeing a complete QemuOptsList, here's my
solution.  The code that needs it isn't ready, yet.  If you'd like to
use it, I can push it to my repo.
Kevin Wolf - July 1, 2010, 7:29 a.m.
Am 01.07.2010 08:47, schrieb Markus Armbruster:
> Kevin Wolf <kwolf@redhat.com> writes:
> 
>> Forgetting to free them means that the next instance inherits all rules and
>> gets its own rules only additionally.
> 
> I also found a use for freeing a complete QemuOptsList, here's my
> solution.  The code that needs it isn't ready, yet.  If you'd like to
> use it, I can push it to my repo.

If you have a use for it, it's the better solution. I'll rebase on top
of this as soon as you have sent it as a proper patch.

Kevin

Patch

diff --git a/qemu-option.c b/qemu-option.c
index 7f70d0f..30327d4 100644
--- a/qemu-option.c
+++ b/qemu-option.c
@@ -719,6 +719,15 @@  QemuOpts *qemu_opts_create(QemuOptsList *list, const char *id, int fail_if_exist
     return opts;
 }
 
+void qemu_opts_reset(QemuOptsList *list)
+{
+    QemuOpts *opts, *next_opts;
+
+    QTAILQ_FOREACH_SAFE(opts, &list->head, next, next_opts) {
+        qemu_opts_del(opts);
+    }
+}
+
 int qemu_opts_set(QemuOptsList *list, const char *id,
                   const char *name, const char *value)
 {
diff --git a/qemu-option.h b/qemu-option.h
index 4823219..9e2406c 100644
--- a/qemu-option.h
+++ b/qemu-option.h
@@ -115,6 +115,7 @@  int qemu_opt_foreach(QemuOpts *opts, qemu_opt_loopfunc func, void *opaque,
 
 QemuOpts *qemu_opts_find(QemuOptsList *list, const char *id);
 QemuOpts *qemu_opts_create(QemuOptsList *list, const char *id, int fail_if_exists);
+void qemu_opts_reset(QemuOptsList *list);
 int qemu_opts_set(QemuOptsList *list, const char *id,
                   const char *name, const char *value);
 const char *qemu_opts_id(QemuOpts *opts);