From d1dd32af6f37e5bb8e6b2024d07fce74f510a668 Mon Sep 17 00:00:00 2001 From: Peter Crosthwaite Date: Mon, 25 Aug 2014 20:10:24 -0700 Subject: memory: Lazy init name from QOM name as needed 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 Signed-off-by: Paolo Bonzini --- memory.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'memory.c') diff --git a/memory.c b/memory.c index 42317a216d..ef0be1c3aa 100644 --- a/memory.c +++ b/memory.c @@ -1309,6 +1309,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; } -- cgit v1.2.3