[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH bugfix v1 2/3] qom: return const for object_get_cano
From: |
Peter Crosthwaite |
Subject: |
[Qemu-devel] [PATCH bugfix v1 2/3] qom: return const for object_get_canon_path component |
Date: |
Tue, 19 Aug 2014 22:07:36 -0700 |
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 <address@hidden>
---
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(-)
diff --git a/backends/hostmem-ram.c b/backends/hostmem-ram.c
index d9a8290..a13ec23 100644
--- a/backends/hostmem-ram.c
+++ b/backends/hostmem-ram.c
@@ -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
diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c
index 5bfc5b7..bc0ef18 100644
--- a/hw/mem/pc-dimm.c
+++ b/hw/mem/pc-dimm.c
@@ -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);
}
diff --git a/include/qom/object.h b/include/qom/object.h
index 8a05a81..8618e49 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -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:
diff --git a/iothread.c b/iothread.c
index d9403cf..37cb0af 100644
--- a/iothread.c
+++ b/iothread.c
@@ -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)
diff --git a/numa.c b/numa.c
index c78cec9..3e05ac5 100644
--- a/numa.c
+++ b/numa.c
@@ -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);
diff --git a/qom/object.c b/qom/object.c
index 1b00831..a7fd480 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -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;
--
2.0.1.1.gfbfc394