On Wed, Feb 26, 2014 at 10:53:34AM +0100, Igor Mammedov wrote: > On Fri, 21 Feb 2014 15:46:56 +0100 > Stefan Hajnoczi <stefa...@redhat.com> 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 <stefa...@redhat.com> > > --- > > 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