From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38878) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XMGDl-0004A5-DC for qemu-devel@nongnu.org; Tue, 26 Aug 2014 08:51:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XMGDg-00030I-9R for qemu-devel@nongnu.org; Tue, 26 Aug 2014 08:51:33 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34589) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XMGDf-00030B-W9 for qemu-devel@nongnu.org; Tue, 26 Aug 2014 08:51:28 -0400 Message-ID: <53FC82C4.2000006@redhat.com> Date: Tue, 26 Aug 2014 14:51:16 +0200 From: Paolo Bonzini MIME-Version: 1.0 References: In-Reply-To: Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH memory v2 3/3] memory: Lazy init name from QOM name as needed List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Crosthwaite , qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, sw@weilnetz.de, stefano.stabellini@eu.citrix.com Il 26/08/2014 05:10, Peter Crosthwaite ha scritto: > To support name retrieval of MemoryRegions that were created > dynamically (that is, not via memory_region_init and friends). We > cache the name in MemoryRegion's state as > object_get_canonical_path_component mallocs the returned value > so it's not suitable for direct return to callers. Memory already > frees the name field, so this will be garbage collected along with > the MR object. > > Signed-off-by: Peter Crosthwaite > --- > > memory.c | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/memory.c b/memory.c > index 42317a2..fc16e5f 100644 > --- a/memory.c > +++ b/memory.c > @@ -914,7 +914,6 @@ void memory_region_init(MemoryRegion *mr, > if (size == UINT64_MAX) { > mr->size = int128_2_64(); > } > - mr->name = g_strdup(name); > > if (name) { > object_property_add_child_array(owner, name, OBJECT(mr)); > @@ -1309,6 +1308,10 @@ uint64_t memory_region_size(MemoryRegion *mr) > > const char *memory_region_name(const MemoryRegion *mr) > { > + if (!mr->name) { > + ((MemoryRegion *)mr)->name = > + object_get_canonical_path_component(OBJECT(mr)); > + } > return mr->name; > } > > Oh if we only used C++... :) Thanks, looks good! Paolo