[libvirt PATCH v6 03/15] xen_common: Change xenConfigGetString to using virConfGetValueString

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This change actually changes the behaviour of xenConfigGetString() as
now it returns a newly-allocated string.

Unfortunately, there's not much that can be done in order to avoid that
and all the needed changes in callers in order to not leak the returned
value are coming in the following patches.

Signed-off-by: Fabiano Fidêncio <fidencio@xxxxxxxxxx>
---
 src/xenconfig/xen_common.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c
index 08fbfff44f..c044cb9672 100644
--- a/src/xenconfig/xen_common.c
+++ b/src/xenconfig/xen_common.c
@@ -228,23 +228,23 @@ xenConfigGetString(virConfPtr conf,
                    const char **value,
                    const char *def)
 {
-    virConfValuePtr val;
+    char *string = NULL;
+    int rc;
 
     *value = NULL;
-    if (!(val = virConfGetValue(conf, name))) {
-        *value = def;
+    if ((rc = virConfGetValueString(conf, name, &string)) < 0)
+        return -1;
+
+    if (rc == 0) {
+        *value = VIR_STRDUP(def);
         return 0;
     }
 
-    if (val->type != VIR_CONF_STRING) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("config value %s was malformed"), name);
-        return -1;
-    }
-    if (!val->str)
-        *value = def;
+    if (!string)
+        *value = VIR_STRDUP(def);
     else
-        *value = val->str;
+        *value = string;
+
     return 0;
 }
 
-- 
2.17.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux