From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>, Fam Zheng <famz@redhat.com>,
Michael Roth <mdroth@linux.vnet.ibm.com>,
Igor Mammedov <imammedo@redhat.com>
Subject: [Qemu-devel] [PATCH v5 5/7] qdev: make get_pointer() handle temporary strings
Date: Fri, 28 Feb 2014 16:18:14 +0100 [thread overview]
Message-ID: <1393600696-24118-6-git-send-email-stefanha@redhat.com> (raw)
In-Reply-To: <1393600696-24118-1-git-send-email-stefanha@redhat.com>
From: Igor Mammedov <imammedo@redhat.com>
get_pointer()'s print() callback might return a heap allocated
string, to avoid adding dedicated get_pointer_foo for this case
convert current print() callbacks to return temporary heap
allocated string and make get_pointer() free it.
Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
hw/core/qdev-properties-system.c | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)
diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-system.c
index 5f5957e..878c3bc 100644
--- a/hw/core/qdev-properties-system.c
+++ b/hw/core/qdev-properties-system.c
@@ -20,15 +20,16 @@
#include "sysemu/char.h"
static void get_pointer(Object *obj, Visitor *v, Property *prop,
- const char *(*print)(void *ptr),
+ char *(*print)(void *ptr),
const char *name, Error **errp)
{
DeviceState *dev = DEVICE(obj);
void **ptr = qdev_get_prop_ptr(dev, prop);
char *p;
- p = (char *) (*ptr ? print(*ptr) : "");
+ p = *ptr ? print(*ptr) : g_strdup("");
visit_type_str(v, &p, name, errp);
+ g_free(p);
}
static void set_pointer(Object *obj, Visitor *v, Property *prop,
@@ -91,9 +92,9 @@ static void release_drive(Object *obj, const char *name, void *opaque)
}
}
-static const char *print_drive(void *ptr)
+static char *print_drive(void *ptr)
{
- return bdrv_get_device_name(ptr);
+ return g_strdup(bdrv_get_device_name(ptr));
}
static void get_drive(Object *obj, Visitor *v, void *opaque,
@@ -145,11 +146,12 @@ static void release_chr(Object *obj, const char *name, void *opaque)
}
-static const char *print_chr(void *ptr)
+static char *print_chr(void *ptr)
{
CharDriverState *chr = ptr;
+ const char *val = chr->label ? chr->label : "";
- return chr->label ? chr->label : "";
+ return g_strdup(val);
}
static void get_chr(Object *obj, Visitor *v, void *opaque,
@@ -224,11 +226,12 @@ err:
return ret;
}
-static const char *print_netdev(void *ptr)
+static char *print_netdev(void *ptr)
{
NetClientState *netdev = ptr;
+ const char *val = netdev->name ? netdev->name : "";
- return netdev->name ? netdev->name : "";
+ return g_strdup(val);
}
static void get_netdev(Object *obj, Visitor *v, void *opaque,
--
1.8.5.3
next prev parent reply other threads:[~2014-02-28 15:18 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-28 15:18 [Qemu-devel] [PATCH v5 0/7] dataplane: switch to N:M devices-per-thread model Stefan Hajnoczi
2014-02-28 15:18 ` [Qemu-devel] [PATCH v5 1/7] object: add object_get_canonical_basename() Stefan Hajnoczi
2014-02-28 17:15 ` Andreas Färber
2014-02-28 18:27 ` Igor Mammedov
2014-03-03 9:52 ` Stefan Hajnoczi
2014-02-28 15:18 ` [Qemu-devel] [PATCH v5 2/7] rfifolock: add recursive FIFO lock Stefan Hajnoczi
2014-02-28 15:18 ` [Qemu-devel] [PATCH v5 3/7] aio: add aio_context_acquire() and aio_context_release() Stefan Hajnoczi
2014-02-28 15:18 ` [Qemu-devel] [PATCH v5 4/7] iothread: add I/O thread object Stefan Hajnoczi
2014-02-28 15:18 ` Stefan Hajnoczi [this message]
2014-02-28 16:49 ` [Qemu-devel] [PATCH v5 5/7] qdev: make get_pointer() handle temporary strings Andreas Färber
2014-03-03 9:41 ` Stefan Hajnoczi
2014-03-03 12:43 ` Igor Mammedov
2014-02-28 15:18 ` [Qemu-devel] [PATCH v5 6/7] iothread: add "iothread" qdev property type Stefan Hajnoczi
2014-02-28 15:18 ` [Qemu-devel] [PATCH v5 7/7] dataplane: replace internal thread with IOThread Stefan Hajnoczi
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=1393600696-24118-6-git-send-email-stefanha@redhat.com \
--to=stefanha@redhat.com \
--cc=famz@redhat.com \
--cc=imammedo@redhat.com \
--cc=kwolf@redhat.com \
--cc=mdroth@linux.vnet.ibm.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).