From: "Zeeshan Ali (Khattak)" <zeeshanak(a)gnome.org>
There is no need for all the memory (de)allocations and especially
forcing the app developers to free the strings. They can always
g_strdup() the returned string if they need.
Most of the patch looks good, see the 3 additional patches I'll send in
answer to this email. The first 2 ones should be merged in this one, the
3rd one can go as an additional cleanup or can be squashed in, as you
prefer. ACK from me with these 3 additional patches, assuming they look
good to you and you are fine with them, otherwise let me know so that we
can figure a way of getting everything in.
Christophe
---
libvirt-gconfig/libvirt-gconfig-domain-disk.c | 13 ++---
libvirt-gconfig/libvirt-gconfig-domain-disk.h | 8 ++--
libvirt-gconfig/libvirt-gconfig-domain-graphics.c | 3 +-
libvirt-gconfig/libvirt-gconfig-domain-interface.c | 9 ++--
libvirt-gconfig/libvirt-gconfig-domain-interface.h | 6 +-
libvirt-gconfig/libvirt-gconfig-domain.c | 8 ++--
libvirt-gconfig/libvirt-gconfig-domain.h | 4 +-
libvirt-gconfig/libvirt-gconfig-helpers-private.h | 16 +++---
libvirt-gconfig/libvirt-gconfig-helpers.c | 54 +++++++++----------
libvirt-gconfig/libvirt-gconfig-object-private.h | 10 ++--
libvirt-gconfig/libvirt-gconfig-object.c | 13 ++---
libvirt-gconfig/tests/test-domain-create.c | 18 ++++---
libvirt-gconfig/tests/test-domain-parse.c | 3 +-
libvirt-gobject/libvirt-gobject-domain-disk.c | 10 ++--
libvirt-gobject/libvirt-gobject-domain-interface.c | 7 +--
15 files changed, 87 insertions(+), 95 deletions(-)
diff --git a/libvirt-gconfig/libvirt-gconfig-domain-disk.c
b/libvirt-gconfig/libvirt-gconfig-domain-disk.c
index afa7eda..2944739 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain-disk.c
+++ b/libvirt-gconfig/libvirt-gconfig-domain-disk.c
@@ -76,16 +76,15 @@ gvir_config_domain_disk_new_from_tree(GVirConfigXmlDoc *doc,
GVirConfigObject *object;
GVirConfigDomainDisk *disk;
GVirConfigDomainDiskType type;
- xmlChar *type_str;
+ const xmlChar *type_str;
type_str = gvir_config_xml_get_attribute_content(tree, "type");
if (type_str == NULL)
return NULL;
type = gvir_config_genum_get_value(GVIR_CONFIG_TYPE_DOMAIN_DISK_TYPE,
- (char *)type_str,
+ (const char *)type_str,
GVIR_CONFIG_DOMAIN_DISK_FILE);
- xmlFree(type_str);
if (type == -1)
return NULL;
@@ -236,7 +235,7 @@ gvir_config_domain_disk_get_snapshot_type(GVirConfigDomainDisk
*disk)
GVIR_CONFIG_DOMAIN_DISK_SNAPSHOT_NO);
}
-char *
+const char *
gvir_config_domain_disk_get_source(GVirConfigDomainDisk *disk)
{
const char *attribute_name;
@@ -263,7 +262,7 @@ gvir_config_domain_disk_get_source(GVirConfigDomainDisk *disk)
"source", attribute_name);
}
-char *
+const char *
gvir_config_domain_disk_get_driver_name(GVirConfigDomainDisk *disk)
{
g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_DISK(disk), NULL);
@@ -272,7 +271,7 @@ gvir_config_domain_disk_get_driver_name(GVirConfigDomainDisk *disk)
"driver", "name");
}
-char *
+const char *
gvir_config_domain_disk_get_driver_type(GVirConfigDomainDisk *disk)
{
g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_DISK(disk), NULL);
@@ -307,7 +306,7 @@ gvir_config_domain_disk_get_target_bus(GVirConfigDomainDisk *disk)
GVIR_CONFIG_DOMAIN_DISK_BUS_IDE);
}
-char *
+const char *
gvir_config_domain_disk_get_target_dev(GVirConfigDomainDisk *disk)
{
g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_DISK(disk), NULL);
diff --git a/libvirt-gconfig/libvirt-gconfig-domain-disk.h
b/libvirt-gconfig/libvirt-gconfig-domain-disk.h
index 4b16b80..916421d 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain-disk.h
+++ b/libvirt-gconfig/libvirt-gconfig-domain-disk.h
@@ -123,12 +123,12 @@ void gvir_config_domain_disk_set_target_dev(GVirConfigDomainDisk
*disk,
GVirConfigDomainDiskType gvir_config_domain_disk_get_disk_type(GVirConfigDomainDisk
*disk);
GVirConfigDomainDiskGuestDeviceType
gvir_config_domain_disk_get_guest_device_type(GVirConfigDomainDisk *disk);
GVirConfigDomainDiskSnapshotType
gvir_config_domain_disk_get_snapshot_type(GVirConfigDomainDisk *disk);
-char *gvir_config_domain_disk_get_source(GVirConfigDomainDisk *disk);
+const char *gvir_config_domain_disk_get_source(GVirConfigDomainDisk *disk);
GVirConfigDomainDiskCacheType
gvir_config_domain_disk_get_driver_cache(GVirConfigDomainDisk *disk);
-char *gvir_config_domain_disk_get_driver_name(GVirConfigDomainDisk *disk);
-char *gvir_config_domain_disk_get_driver_type(GVirConfigDomainDisk *disk);
+const char *gvir_config_domain_disk_get_driver_name(GVirConfigDomainDisk *disk);
+const char *gvir_config_domain_disk_get_driver_type(GVirConfigDomainDisk *disk);
GVirConfigDomainDiskBus gvir_config_domain_disk_get_target_bus(GVirConfigDomainDisk
*disk);
-char *gvir_config_domain_disk_get_target_dev(GVirConfigDomainDisk *disk);
+const char *gvir_config_domain_disk_get_target_dev(GVirConfigDomainDisk *disk);
void gvir_config_domain_disk_set_readonly(GVirConfigDomainDisk *disk,
gboolean readonly);
diff --git a/libvirt-gconfig/libvirt-gconfig-domain-graphics.c
b/libvirt-gconfig/libvirt-gconfig-domain-graphics.c
index 05a2f01..c79406e 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain-graphics.c
+++ b/libvirt-gconfig/libvirt-gconfig-domain-graphics.c
@@ -53,7 +53,7 @@ G_GNUC_INTERNAL GVirConfigDomainDevice *
gvir_config_domain_graphics_new_from_tree(GVirConfigXmlDoc *doc,
xmlNodePtr tree)
{
- xmlChar *type;
+ const xmlChar *type;
GType gtype;
type = gvir_config_xml_get_attribute_content(tree, "type");
@@ -74,7 +74,6 @@ gvir_config_domain_graphics_new_from_tree(GVirConfigXmlDoc *doc,
g_debug("Unknown graphics node: %s", type);
return NULL;
}
- xmlFree(type);
return GVIR_CONFIG_DOMAIN_DEVICE(gvir_config_object_new_from_tree(gtype, doc, NULL,
tree));
diff --git a/libvirt-gconfig/libvirt-gconfig-domain-interface.c
b/libvirt-gconfig/libvirt-gconfig-domain-interface.c
index 5fe27a1..6f539a2 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain-interface.c
+++ b/libvirt-gconfig/libvirt-gconfig-domain-interface.c
@@ -96,7 +96,7 @@ void gvir_config_domain_interface_set_model(GVirConfigDomainInterface
*interface
"model", "type",
model);
}
-char *gvir_config_domain_interface_get_ifname(GVirConfigDomainInterface *interface)
+const char *gvir_config_domain_interface_get_ifname(GVirConfigDomainInterface
*interface)
{
g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_INTERFACE(interface), NULL);
@@ -115,7 +115,7 @@ GVirConfigDomainInterfaceLinkState
gvir_config_domain_interface_get_link_state(G
GVIR_CONFIG_DOMAIN_INTERFACE_LINK_STATE_DEFAULT);
}
-char *gvir_config_domain_interface_get_mac(GVirConfigDomainInterface *interface)
+const char *gvir_config_domain_interface_get_mac(GVirConfigDomainInterface *interface)
{
g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_INTERFACE(interface), NULL);
@@ -123,7 +123,7 @@ char *gvir_config_domain_interface_get_mac(GVirConfigDomainInterface
*interface)
"mac", "address");
}
-char *gvir_config_domain_interface_get_model(GVirConfigDomainInterface *interface)
+const char *gvir_config_domain_interface_get_model(GVirConfigDomainInterface
*interface)
{
g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_INTERFACE(interface), NULL);
@@ -135,7 +135,7 @@ G_GNUC_INTERNAL GVirConfigDomainDevice *
gvir_config_domain_interface_new_from_tree(GVirConfigXmlDoc *doc,
xmlNodePtr tree)
{
- xmlChar *type;
+ const xmlChar *type;
GType gtype;
type = gvir_config_xml_get_attribute_content(tree, "type");
@@ -160,7 +160,6 @@ gvir_config_domain_interface_new_from_tree(GVirConfigXmlDoc *doc,
g_debug("Unknown domain interface node: %s", type);
return NULL;
}
- xmlFree(type);
return GVIR_CONFIG_DOMAIN_DEVICE(gvir_config_object_new_from_tree(gtype, doc, NULL,
tree));
diff --git a/libvirt-gconfig/libvirt-gconfig-domain-interface.h
b/libvirt-gconfig/libvirt-gconfig-domain-interface.h
index 567f95a..c8c4fb3 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain-interface.h
+++ b/libvirt-gconfig/libvirt-gconfig-domain-interface.h
@@ -72,10 +72,10 @@ void gvir_config_domain_interface_set_mac(GVirConfigDomainInterface
*interface,
const char *mac_address);
void gvir_config_domain_interface_set_model(GVirConfigDomainInterface *interface,
const char *model);
-char *gvir_config_domain_interface_get_ifname(GVirConfigDomainInterface *interface);
+const char *gvir_config_domain_interface_get_ifname(GVirConfigDomainInterface
*interface);
GVirConfigDomainInterfaceLinkState
gvir_config_domain_interface_get_link_state(GVirConfigDomainInterface *interface);
-char *gvir_config_domain_interface_get_mac(GVirConfigDomainInterface *interface);
-char *gvir_config_domain_interface_get_model(GVirConfigDomainInterface *interface);
+const char *gvir_config_domain_interface_get_mac(GVirConfigDomainInterface *interface);
+const char *gvir_config_domain_interface_get_model(GVirConfigDomainInterface
*interface);
G_END_DECLS
diff --git a/libvirt-gconfig/libvirt-gconfig-domain.c
b/libvirt-gconfig/libvirt-gconfig-domain.c
index 177c926..33a69e3 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain.c
+++ b/libvirt-gconfig/libvirt-gconfig-domain.c
@@ -54,10 +54,10 @@ static void gvir_config_domain_get_property(GObject *object,
switch (prop_id) {
case PROP_NAME:
- g_value_take_string(value, gvir_config_domain_get_name(domain));
+ g_value_set_string(value, gvir_config_domain_get_name(domain));
break;
case PROP_DESCRIPTION:
- g_value_take_string(value, gvir_config_domain_get_description(domain));
+ g_value_set_string(value, gvir_config_domain_get_description(domain));
break;
case PROP_MEMORY:
g_value_set_uint64(value, gvir_config_domain_get_memory(domain));
@@ -198,7 +198,7 @@ void gvir_config_domain_set_virt_type(GVirConfigDomain *domain,
GVirConfigDomain
}
-char *gvir_config_domain_get_name(GVirConfigDomain *domain)
+const char *gvir_config_domain_get_name(GVirConfigDomain *domain)
{
return gvir_config_object_get_node_content(GVIR_CONFIG_OBJECT(domain),
"name");
@@ -211,7 +211,7 @@ void gvir_config_domain_set_name(GVirConfigDomain *domain, const char
*name)
g_object_notify(G_OBJECT(domain), "name");
}
-char *gvir_config_domain_get_description(GVirConfigDomain *domain)
+const char *gvir_config_domain_get_description(GVirConfigDomain *domain)
{
return gvir_config_object_get_node_content(GVIR_CONFIG_OBJECT(domain),
"description");
diff --git a/libvirt-gconfig/libvirt-gconfig-domain.h
b/libvirt-gconfig/libvirt-gconfig-domain.h
index 769d2f0..1dbfd95 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain.h
+++ b/libvirt-gconfig/libvirt-gconfig-domain.h
@@ -100,9 +100,9 @@ GVirConfigDomain *gvir_config_domain_new_from_xml(const gchar *xml,
GError **err
GVirConfigDomain *gvir_config_domain_new(void);
void gvir_config_domain_set_virt_type(GVirConfigDomain *domain, GVirConfigDomainVirtType
type);
-char *gvir_config_domain_get_name(GVirConfigDomain *domain);
+const char *gvir_config_domain_get_name(GVirConfigDomain *domain);
void gvir_config_domain_set_name(GVirConfigDomain *domain, const char *name);
-char *gvir_config_domain_get_description(GVirConfigDomain *domain);
+const char *gvir_config_domain_get_description(GVirConfigDomain *domain);
void gvir_config_domain_set_description(GVirConfigDomain *domain, const char
*description);
guint64 gvir_config_domain_get_memory(GVirConfigDomain *domain);
void gvir_config_domain_set_memory(GVirConfigDomain *domain, guint64 memory);
diff --git a/libvirt-gconfig/libvirt-gconfig-helpers-private.h
b/libvirt-gconfig/libvirt-gconfig-helpers-private.h
index 514aeb0..aa53874 100644
--- a/libvirt-gconfig/libvirt-gconfig-helpers-private.h
+++ b/libvirt-gconfig/libvirt-gconfig-helpers-private.h
@@ -50,15 +50,15 @@ void gvir_config_xml_foreach_child(xmlNodePtr node,
GVirConfigXmlNodeIterator iter_func,
gpointer opaque);
xmlNode * gvir_config_xml_get_element (xmlNode *node, ...);
-xmlChar * gvir_config_xml_get_child_element_content (xmlNode *node,
- const char *child_name);
-char *gvir_config_xml_get_child_element_content_glib (xmlNode *node,
- const char *child_name);
-xmlChar *gvir_config_xml_get_attribute_content(xmlNodePtr node,
- const char *attr_name);
+const xmlChar * gvir_config_xml_get_child_element_content (xmlNode *node,
+ const char *child_name);
+const char *gvir_config_xml_get_child_element_content_glib (xmlNode *node,
+ const char *child_name);
+const xmlChar *gvir_config_xml_get_attribute_content(xmlNodePtr node,
+ const char *attr_name);
char *gvir_config_xml_node_to_string(xmlNodePtr node);
-char *gvir_config_xml_get_attribute_content_glib(xmlNodePtr node,
- const char *attr_name);
+const char *gvir_config_xml_get_attribute_content_glib(xmlNodePtr node,
+ const char *attr_name);
const char *gvir_config_genum_get_nick (GType enum_type, gint value);
int gvir_config_genum_get_value (GType enum_type, const char *nick, gint
default_value);
G_END_DECLS
diff --git a/libvirt-gconfig/libvirt-gconfig-helpers.c
b/libvirt-gconfig/libvirt-gconfig-helpers.c
index 5f4ebe9..49c7f90 100644
--- a/libvirt-gconfig/libvirt-gconfig-helpers.c
+++ b/libvirt-gconfig/libvirt-gconfig-helpers.c
@@ -220,56 +220,54 @@ gvir_config_xml_get_element (xmlNode *node, ...)
return node;
}
-xmlChar *
-gvir_config_xml_get_child_element_content (xmlNode *node,
+const xmlChar *
+gvir_config_xml_get_child_element_content (xmlNode *node,
const char *child_name)
{
- xmlNode *child_node;
+ xmlNode *child_node;
- child_node = gvir_config_xml_get_element (node, child_name, NULL);
- if (!child_node)
- return NULL;
-
- return xmlNodeGetContent (child_node);
-}
-
-static char *libxml_str_to_glib(xmlChar *str)
-{
- char *g_str;
-
- if (str == NULL)
+ child_node = gvir_config_xml_get_element(node, child_name, NULL);
+ if (!child_node || !(child_node->children))
return NULL;
- g_str = g_strdup((char *)str);
- xmlFree(str);
- return g_str;
+ return child_node->children->content;
}
-char *
-gvir_config_xml_get_child_element_content_glib (xmlNode *node,
+const char *
+gvir_config_xml_get_child_element_content_glib (xmlNode *node,
const char *child_name)
{
- xmlChar *content;
+ const xmlChar *content;
- content = gvir_config_xml_get_child_element_content (node, child_name);
+ content = gvir_config_xml_get_child_element_content(node, child_name);
- return libxml_str_to_glib(content);
+ return (const char *)content;
}
-G_GNUC_INTERNAL xmlChar *
+G_GNUC_INTERNAL const xmlChar *
gvir_config_xml_get_attribute_content(xmlNodePtr node, const char *attr_name)
{
- return xmlGetProp(node, (const xmlChar*)attr_name);
+ xmlAttr *attr;
+
+ for (attr = node->properties; attr; attr = attr->next) {
+ if (attr->name == NULL)
+ continue;
+
+ if (strcmp (attr_name, (char *)attr->name) == 0)
+ break;
+ }
+
+ return attr->children->content;
}
-G_GNUC_INTERNAL char *
+G_GNUC_INTERNAL const char *
gvir_config_xml_get_attribute_content_glib(xmlNodePtr node, const char *attr_name)
{
- xmlChar *attr;
+ const xmlChar *attr;
attr = gvir_config_xml_get_attribute_content(node, attr_name);
- return libxml_str_to_glib(attr);
+ return (const char *) attr;
}
const char *gvir_config_genum_get_nick (GType enum_type, gint value)
diff --git a/libvirt-gconfig/libvirt-gconfig-object-private.h
b/libvirt-gconfig/libvirt-gconfig-object-private.h
index 41cbfe8..a6b7395 100644
--- a/libvirt-gconfig/libvirt-gconfig-object-private.h
+++ b/libvirt-gconfig/libvirt-gconfig-object-private.h
@@ -31,17 +31,17 @@ GVirConfigObject *gvir_config_object_new_from_tree(GType type,
const char *schema,
xmlNodePtr tree);
xmlNodePtr gvir_config_object_get_xml_node(GVirConfigObject *config);
-char *gvir_config_object_get_node_content(GVirConfigObject *object,
- const char *node_name);
+const char *gvir_config_object_get_node_content(GVirConfigObject *object,
+ const char *node_name);
guint64 gvir_config_object_get_node_content_uint64(GVirConfigObject *object,
const char *node_name);
gint gvir_config_object_get_node_content_genum(GVirConfigObject *object,
const char *node_name,
GType enum_type,
gint default_value);
-char *gvir_config_object_get_attribute(GVirConfigObject *object,
- const char *node_name,
- const char *attr_name);
+const char *gvir_config_object_get_attribute(GVirConfigObject *object,
+ const char *node_name,
+ const char *attr_name);
gint gvir_config_object_get_attribute_genum(GVirConfigObject *object,
const char *node_name,
const char *attr_name,
diff --git a/libvirt-gconfig/libvirt-gconfig-object.c
b/libvirt-gconfig/libvirt-gconfig-object.c
index b637960..d99a0a2 100644
--- a/libvirt-gconfig/libvirt-gconfig-object.c
+++ b/libvirt-gconfig/libvirt-gconfig-object.c
@@ -274,7 +274,7 @@ gvir_config_object_get_xml_node(GVirConfigObject *config)
return config->priv->node;
}
-G_GNUC_INTERNAL char *
+G_GNUC_INTERNAL const char *
gvir_config_object_get_node_content(GVirConfigObject *object,
const char *node_name)
{
@@ -287,7 +287,7 @@ gvir_config_object_get_node_content(GVirConfigObject *object,
return gvir_config_xml_get_child_element_content_glib(node, node_name);
}
-G_GNUC_INTERNAL char *
+G_GNUC_INTERNAL const char *
gvir_config_object_get_attribute(GVirConfigObject *object,
const char *node_name,
const char *attr_name)
@@ -559,7 +559,7 @@ gvir_config_object_get_node_content_uint64(GVirConfigObject *object,
const char *node_name)
{
xmlNodePtr node;
- xmlChar *str;
+ const xmlChar *str;
guint64 value;
node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(object));
@@ -571,7 +571,6 @@ gvir_config_object_get_node_content_uint64(GVirConfigObject *object,
return 0;
value = g_ascii_strtoull((char *)str, NULL, 0);
- xmlFree(str);
return value;
}
@@ -583,7 +582,7 @@ gvir_config_object_get_node_content_genum(GVirConfigObject *object,
gint default_value)
{
xmlNodePtr node;
- xmlChar *str;
+ const xmlChar *str;
gint value;
node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(object));
@@ -595,7 +594,6 @@ gvir_config_object_get_node_content_genum(GVirConfigObject *object,
return default_value;
value = gvir_config_genum_get_value(enum_type, (char *)str, default_value);
- xmlFree(str);
return value;
}
@@ -608,7 +606,7 @@ gvir_config_object_get_attribute_genum(GVirConfigObject *object,
gint default_value)
{
xmlNodePtr node;
- xmlChar *attr_val;
+ const xmlChar *attr_val;
gint value;
g_return_val_if_fail(attr_name != NULL, default_value);
@@ -629,7 +627,6 @@ gvir_config_object_get_attribute_genum(GVirConfigObject *object,
value = gvir_config_genum_get_value(enum_type, (char *)attr_val,
default_value);
- xmlFree(attr_val);
return value;
}
diff --git a/libvirt-gconfig/tests/test-domain-create.c
b/libvirt-gconfig/tests/test-domain-create.c
index a92413d..8c9a6ba 100644
--- a/libvirt-gconfig/tests/test-domain-create.c
+++ b/libvirt-gconfig/tests/test-domain-create.c
@@ -32,10 +32,14 @@
const char *features[] = { "foo", "bar", "baz", NULL };
+#define g_str_const_check(str1, str2) G_STMT_START { \
+ g_assert((str1) != NULL); \
+ g_assert(g_strcmp0((str1), (str2)) == 0); \
+} G_STMT_END
+
#define g_str_check(str1, str2) G_STMT_START { \
char *alloced_str = (str1); \
- g_assert(alloced_str != NULL); \
- g_assert(g_strcmp0(alloced_str, (str2)) == 0); \
+ g_str_const_check(alloced_str, (str2)); \
g_free(alloced_str); \
} G_STMT_END
@@ -51,7 +55,7 @@ int main(int argc, char **argv)
domain = gvir_config_domain_new();
g_assert(domain != NULL);
gvir_config_domain_set_name(domain, "foo");
- g_str_check(gvir_config_domain_get_name(domain), "foo");
+ g_str_const_check(gvir_config_domain_get_name(domain), "foo");
gvir_config_domain_set_memory(domain, 1234);
g_assert(gvir_config_domain_get_memory(domain) == 1234);
@@ -113,12 +117,12 @@ int main(int argc, char **argv)
g_assert(gvir_config_domain_disk_get_disk_type(disk) ==
GVIR_CONFIG_DOMAIN_DISK_FILE);
g_assert(gvir_config_domain_disk_get_guest_device_type(disk) ==
GVIR_CONFIG_DOMAIN_DISK_GUEST_DEVICE_DISK);
- g_str_check(gvir_config_domain_disk_get_source(disk), "/tmp/foo/bar");
+ g_str_const_check(gvir_config_domain_disk_get_source(disk),
"/tmp/foo/bar");
g_assert(gvir_config_domain_disk_get_driver_cache(disk) ==
GVIR_CONFIG_DOMAIN_DISK_CACHE_NONE);
- g_str_check(gvir_config_domain_disk_get_driver_name(disk), "qemu");
- g_str_check(gvir_config_domain_disk_get_driver_type(disk), "qcow2");
+ g_str_const_check(gvir_config_domain_disk_get_driver_name(disk), "qemu");
+ g_str_const_check(gvir_config_domain_disk_get_driver_type(disk),
"qcow2");
g_assert(gvir_config_domain_disk_get_target_bus(disk) ==
GVIR_CONFIG_DOMAIN_DISK_BUS_IDE);
- g_str_check(gvir_config_domain_disk_get_target_dev(disk), "hda");
+ g_str_const_check(gvir_config_domain_disk_get_target_dev(disk), "hda");
/* network interfaces node */
diff --git a/libvirt-gconfig/tests/test-domain-parse.c
b/libvirt-gconfig/tests/test-domain-parse.c
index c264ff9..11880de 100644
--- a/libvirt-gconfig/tests/test-domain-parse.c
+++ b/libvirt-gconfig/tests/test-domain-parse.c
@@ -34,7 +34,7 @@
int main(int argc, char **argv)
{
GVirConfigDomain *domain;
- char *name;
+ const char *name;
GStrv features;
char *xml;
GError *error = NULL;
@@ -69,7 +69,6 @@ int main(int argc, char **argv)
name = gvir_config_domain_get_name(domain);
g_assert(name != NULL);
g_assert(strcmp(name, "foo") == 0);
- g_free(name);
g_assert(gvir_config_domain_get_memory(domain) == 987654321);
diff --git a/libvirt-gobject/libvirt-gobject-domain-disk.c
b/libvirt-gobject/libvirt-gobject-domain-disk.c
index d8fb63d..fb85328 100644
--- a/libvirt-gobject/libvirt-gobject-domain-disk.c
+++ b/libvirt-gobject/libvirt-gobject-domain-disk.c
@@ -90,10 +90,10 @@ gvir_domain_disk_stats_free(GVirDomainDiskStats *stats)
G_DEFINE_BOXED_TYPE(GVirDomainDiskStats, gvir_domain_disk_stats,
gvir_domain_disk_stats_copy, gvir_domain_disk_stats_free)
-static gchar *gvir_domain_disk_get_path(GVirDomainDisk *self)
+static const gchar *gvir_domain_disk_get_path(GVirDomainDisk *self)
{
GVirConfigDomainDevice *config;
- gchar *path;
+ const gchar *path;
config = gvir_domain_device_get_config(GVIR_DOMAIN_DEVICE(self));
path = gvir_config_domain_disk_get_target_dev(GVIR_CONFIG_DOMAIN_DISK(config));
@@ -119,7 +119,7 @@ GVirDomainDiskStats *gvir_domain_disk_get_stats(GVirDomainDisk *self,
GError **e
GVirDomainDiskStats *ret = NULL;
virDomainBlockStatsStruct stats;
virDomainPtr handle;
- gchar *path;
+ const gchar *path;
g_return_val_if_fail(GVIR_IS_DOMAIN_DISK(self), NULL);
@@ -142,7 +142,6 @@ GVirDomainDiskStats *gvir_domain_disk_get_stats(GVirDomainDisk *self,
GError **e
end:
virDomainFree(handle);
- g_free(path);
return ret;
}
@@ -164,7 +163,7 @@ gboolean gvir_domain_disk_resize(GVirDomainDisk *self,
{
gboolean ret = FALSE;
virDomainPtr handle;
- gchar *path;
+ const gchar *path;
g_return_val_if_fail(GVIR_IS_DOMAIN_DISK(self), FALSE);
g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
@@ -183,6 +182,5 @@ gboolean gvir_domain_disk_resize(GVirDomainDisk *self,
end:
virDomainFree(handle);
- g_free(path);
return ret;
}
diff --git a/libvirt-gobject/libvirt-gobject-domain-interface.c
b/libvirt-gobject/libvirt-gobject-domain-interface.c
index 4436466..9f4b30d 100644
--- a/libvirt-gobject/libvirt-gobject-domain-interface.c
+++ b/libvirt-gobject/libvirt-gobject-domain-interface.c
@@ -88,10 +88,10 @@ gvir_domain_interface_stats_free(GVirDomainInterfaceStats *stats)
G_DEFINE_BOXED_TYPE(GVirDomainInterfaceStats, gvir_domain_interface_stats,
gvir_domain_interface_stats_copy, gvir_domain_interface_stats_free)
-static gchar *gvir_domain_interface_get_path(GVirDomainInterface *self)
+static const gchar *gvir_domain_interface_get_path(GVirDomainInterface *self)
{
GVirConfigDomainDevice *config;
- gchar *path = NULL;
+ const gchar *path = NULL;
config = gvir_domain_device_get_config(GVIR_DOMAIN_DEVICE(self));
if (GVIR_CONFIG_IS_DOMAIN_INTERFACE_USER(self))
@@ -121,7 +121,7 @@ GVirDomainInterfaceStats
*gvir_domain_interface_get_stats(GVirDomainInterface *s
GVirDomainInterfaceStats *ret = NULL;
virDomainInterfaceStatsStruct stats;
virDomainPtr handle;
- gchar *path;
+ const gchar *path;
g_return_val_if_fail(GVIR_IS_DOMAIN_INTERFACE(self), NULL);
@@ -151,6 +151,5 @@ GVirDomainInterfaceStats
*gvir_domain_interface_get_stats(GVirDomainInterface *s
end:
virDomainFree(handle);
- g_free(path);
return ret;
}
--
1.7.7.6
--
libvir-list mailing list
libvir-list(a)redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list