@@ -18,7 +18,7 @@
static void
ram_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)
{
- char *path;
+ const char *path;
if (!backend->size) {
error_setg(errp, "can't create backend with size 0");
@@ -28,7 +28,6 @@ ram_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)
path = object_get_canonical_path_component(OBJECT(backend));
memory_region_init_ram(&backend->mr, OBJECT(backend), path,
backend->size);
- g_free(path);
}
static void
@@ -223,9 +223,8 @@ static void pc_dimm_check_memdev_is_busy(Object *obj, const char *name,
mr = host_memory_backend_get_memory(MEMORY_BACKEND(val), errp);
if (memory_region_is_mapped(mr)) {
- char *path = object_get_canonical_path_component(val);
+ const char *path = object_get_canonical_path_component(val);
error_setg(errp, "can't use already busy memdev: %s", path);
- g_free(path);
} else {
qdev_prop_allow_set_link_before_realize(obj, name, val, errp);
}
@@ -1031,7 +1031,7 @@ Object *object_get_root(void);
* Returns: The final component in the object's canonical path. The canonical
* path is the path within the composition tree starting from the root.
*/
-gchar *object_get_canonical_path_component(Object *obj);
+const gchar *object_get_canonical_path_component(Object *obj);
/**
* object_get_canonical_path:
@@ -126,7 +126,7 @@ IOThread *iothread_find(const char *id)
char *iothread_get_id(IOThread *iothread)
{
- return object_get_canonical_path_component(OBJECT(iothread));
+ return g_strdup(object_get_canonical_path_component(OBJECT(iothread)));
}
AioContext *iothread_get_aio_context(IOThread *iothread)
@@ -302,7 +302,9 @@ void memory_region_allocate_system_memory(MemoryRegion *mr, Object *owner,
}
if (memory_region_is_mapped(seg)) {
- char *path = object_get_canonical_path_component(OBJECT(backend));
+ const char *path;
+
+ path = object_get_canonical_path_component(OBJECT(backend));
error_report("memory backend %s is used multiple times. Each "
"-numa option must use a different memdev value.",
path);
@@ -1219,7 +1219,7 @@ out:
g_free(full_type);
}
-gchar *object_get_canonical_path_component(Object *obj)
+const gchar *object_get_canonical_path_component(Object *obj)
{
ObjectProperty *prop = NULL;
@@ -1232,7 +1232,7 @@ gchar *object_get_canonical_path_component(Object *obj)
}
if (prop->opaque == obj) {
- return g_strdup(prop->name);
+ return prop->name;
}
}
@@ -1247,15 +1247,14 @@ gchar *object_get_canonical_path(Object *obj)
char *newpath, *path = NULL;
while (obj != root) {
- char *component = object_get_canonical_path_component(obj);
+ const char *component = object_get_canonical_path_component(obj);
if (path) {
newpath = g_strdup_printf("%s/%s", component, path);
- g_free(component);
g_free(path);
path = newpath;
} else {
- path = component;
+ path = g_strdup(component);
}
obj = obj->parent;
Most (if not all) calls sites of object_get_canonical_path component use it to get a read-only version for usage as an object name. Avoid the need for the callers to explicitly free the returned string and mark it const accordingly. Frees are removed from call sites accordingly. Signed-off-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com> --- backends/hostmem-ram.c | 3 +-- hw/mem/pc-dimm.c | 3 +-- include/qom/object.h | 2 +- iothread.c | 2 +- numa.c | 4 +++- qom/object.c | 9 ++++----- 6 files changed, 11 insertions(+), 12 deletions(-)