From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37253) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WJKsW-0000fa-N5 for qemu-devel@nongnu.org; Fri, 28 Feb 2014 05:41:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WJKsQ-0002G0-JP for qemu-devel@nongnu.org; Fri, 28 Feb 2014 05:41:16 -0500 Received: from mx1.redhat.com ([209.132.183.28]:17822) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WJKsQ-0002Ft-AD for qemu-devel@nongnu.org; Fri, 28 Feb 2014 05:41:10 -0500 Date: Fri, 28 Feb 2014 11:41:06 +0100 From: Stefan Hajnoczi Message-ID: <20140228104106.GG30385@stefanha-thinkpad.redhat.com> References: <1392994018-7786-1-git-send-email-stefanha@redhat.com> <1392994018-7786-5-git-send-email-stefanha@redhat.com> <20140226105334.24f7d55f@nial.usersys.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20140226105334.24f7d55f@nial.usersys.redhat.com> Subject: Re: [Qemu-devel] [PATCH v4 4/6] qdev: add get_pointer_and_free() for temporary strings List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Igor Mammedov Cc: Kevin Wolf , Paolo Bonzini , Fam Zheng , qemu-devel@nongnu.org, Michael Roth On Wed, Feb 26, 2014 at 10:53:34AM +0100, Igor Mammedov wrote: > On Fri, 21 Feb 2014 15:46:56 +0100 > Stefan Hajnoczi wrote: > > > get_pointer() assumes the string has unspecified lifetime (at least as > > long as the object is alive). In some cases we can only produce a > > temporary string that should be freed when get_pointer() is done. > > > > Signed-off-by: Stefan Hajnoczi > > --- > > hw/core/qdev-properties-system.c | 14 ++++++++++++++ > > 1 file changed, 14 insertions(+) > > > > diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-system.c > > index 5f5957e..3bffc01 100644 > > --- a/hw/core/qdev-properties-system.c > > +++ b/hw/core/qdev-properties-system.c > > @@ -31,6 +31,20 @@ static void get_pointer(Object *obj, Visitor *v, Property *prop, > > visit_type_str(v, &p, name, errp); > > } > > > > +/* Same as get_pointer() but frees heap-allocated print() return value */ > > +static void get_pointer_and_free(Object *obj, Visitor *v, Property *prop, > > + char *(*print)(void *ptr), > > + const char *name, Error **errp) > > +{ > > + DeviceState *dev = DEVICE(obj); > > + void **ptr = qdev_get_prop_ptr(dev, prop); > > + char *p; > > + > > + p = *ptr ? print(*ptr) : g_strdup(""); > > + visit_type_str(v, &p, name, errp); > > + g_free(p); > > +} > it could be better if get_pointer() would free pointer if 3 current users > are converted to return temporary string, something like this: Yes, that is nicer. I'll switch to your patch in the next revision. Stefan