qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: pbonzini@redhat.com, Gerd Hoffmann <kraxel@redhat.com>,
	mprivozn@redhat.com
Subject: [Qemu-devel] [PATCH 2/9] chardev: fix QemuOpts lifecycle
Date: Wed, 19 Dec 2012 16:59:00 +0100	[thread overview]
Message-ID: <1355932747-1755-3-git-send-email-kraxel@redhat.com> (raw)
In-Reply-To: <1355932747-1755-1-git-send-email-kraxel@redhat.com>

qemu_chr_new_from_opts handles QemuOpts release now, so callers don't
have to worry.  It will either be saved in CharDriverState, then
released in qemu_chr_delete, or in the error case released instantly.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 qemu-char.c |   15 ++++++++++-----
 qemu-char.h |    1 +
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/qemu-char.c b/qemu-char.c
index 713eae9..9bb3a6b 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -2777,13 +2777,13 @@ CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts,
 
     if (qemu_opts_id(opts) == NULL) {
         error_setg(errp, "chardev: no id specified\n");
-        return NULL;
+        goto err;
     }
 
     if (qemu_opt_get(opts, "backend") == NULL) {
         error_setg(errp, "chardev: \"%s\" missing backend\n",
                    qemu_opts_id(opts));
-        return NULL;
+        goto err;
     }
     for (i = 0; i < ARRAY_SIZE(backend_table); i++) {
         if (strcmp(backend_table[i].name, qemu_opt_get(opts, "backend")) == 0)
@@ -2792,14 +2792,14 @@ CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts,
     if (i == ARRAY_SIZE(backend_table)) {
         error_setg(errp, "chardev: backend \"%s\" not found\n",
                    qemu_opt_get(opts, "backend"));
-        return NULL;
+        goto err;
     }
 
     chr = backend_table[i].open(opts);
     if (!chr) {
         error_setg(errp, "chardev: opening backend \"%s\" failed\n",
                    qemu_opt_get(opts, "backend"));
-        return NULL;
+        goto err;
     }
 
     if (!chr->filename)
@@ -2820,7 +2820,12 @@ CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts,
         chr->avail_connections = 1;
     }
     chr->label = g_strdup(qemu_opts_id(opts));
+    chr->opts = opts;
     return chr;
+
+err:
+    qemu_opts_del(opts);
+    return NULL;
 }
 
 CharDriverState *qemu_chr_new(const char *label, const char *filename, void (*init)(struct CharDriverState *s))
@@ -2846,7 +2851,6 @@ CharDriverState *qemu_chr_new(const char *label, const char *filename, void (*in
     if (chr && qemu_opt_get_bool(opts, "mux", 0)) {
         monitor_init(chr, MONITOR_USE_READLINE);
     }
-    qemu_opts_del(opts);
     return chr;
 }
 
@@ -2878,6 +2882,7 @@ void qemu_chr_delete(CharDriverState *chr)
         chr->chr_close(chr);
     g_free(chr->filename);
     g_free(chr->label);
+    qemu_opts_del(chr->opts);
     g_free(chr);
 }
 
diff --git a/qemu-char.h b/qemu-char.h
index d7eed34..f984071 100644
--- a/qemu-char.h
+++ b/qemu-char.h
@@ -75,6 +75,7 @@ struct CharDriverState {
     char *filename;
     int opened;
     int avail_connections;
+    QemuOpts *opts;
     QTAILQ_ENTRY(CharDriverState) next;
 };
 
-- 
1.7.1

  parent reply	other threads:[~2012-12-19 15:59 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-19 15:58 [Qemu-devel] [PATCH RfC 0/9] chardev hotplug Gerd Hoffmann
2012-12-19 15:58 ` [Qemu-devel] [PATCH 1/9] chardev: add error reporting for qemu_chr_new_from_opts Gerd Hoffmann
2012-12-19 15:59 ` Gerd Hoffmann [this message]
2012-12-19 15:59 ` [Qemu-devel] [PATCH 3/9] chardev: reduce chardev ifdef mess a bit Gerd Hoffmann
2012-12-19 20:04   ` Blue Swirl
2012-12-19 15:59 ` [Qemu-devel] [PATCH 4/9] chardev: hotplug, qmp, null Gerd Hoffmann
2012-12-19 15:59 ` [Qemu-devel] [PATCH 5/9] chardev: hotplug, hmp Gerd Hoffmann
2012-12-19 15:59 ` [Qemu-devel] [PATCH 6/9] chardev: hotplug, qmp, file Gerd Hoffmann
2012-12-19 15:59 ` [Qemu-devel] [PATCH 7/9] chardev: hotplug, qmp, tty Gerd Hoffmann
2012-12-19 15:59 ` [Qemu-devel] [PATCH 8/9] chardev: hotplug, qmp, serial Gerd Hoffmann
2012-12-19 16:21   ` Paolo Bonzini
2012-12-20  7:09     ` Gerd Hoffmann
2012-12-19 15:59 ` [Qemu-devel] [PATCH 9/9] chardev: hotplug, qmp, parallel Gerd Hoffmann
2012-12-20 10:49 ` [Qemu-devel] [PATCH RfC 0/9] chardev hotplug Michal Privoznik
2012-12-20 10:56   ` Daniel P. Berrange
2012-12-20 11:10     ` Paolo Bonzini
2012-12-20 11:45       ` Gerd Hoffmann
2012-12-20 13:02         ` Gerd Hoffmann
2012-12-21 11:45           ` Gerd Hoffmann
2012-12-21 11:53             ` Paolo Bonzini
2012-12-21 12:17               ` Gerd Hoffmann
2012-12-21 12:40                 ` Paolo Bonzini
2012-12-21 14:21                   ` Gerd Hoffmann
2012-12-20 16:44         ` Daniel P. Berrange
2012-12-21  9:01           ` Gerd Hoffmann
2012-12-21  9:28             ` Daniel P. Berrange

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1355932747-1755-3-git-send-email-kraxel@redhat.com \
    --to=kraxel@redhat.com \
    --cc=mprivozn@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).