[libvirt PATCH 20/21] util: Use glib memory functions in virFileGetXAttrQuiet

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

 



Signed-off-by: Tim Wiederhake <twiederh@xxxxxxxxxx>
---
 src/util/virfile.c | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)

diff --git a/src/util/virfile.c b/src/util/virfile.c
index 90156845df..61d2c16072 100644
--- a/src/util/virfile.c
+++ b/src/util/virfile.c
@@ -4327,8 +4327,7 @@ virFileGetXAttrQuiet(const char *path,
                      const char *name,
                      char **value)
 {
-    char *buf = NULL;
-    int ret = -1;
+    g_autofree char *buf = NULL;
 
     /* We might be racing with somebody who sets the same attribute. */
     while (1) {
@@ -4337,15 +4336,14 @@ virFileGetXAttrQuiet(const char *path,
 
         /* The first call determines how many bytes we need to allocate. */
         if ((need = getxattr(path, name, NULL, 0)) < 0)
-            goto cleanup;
+            return -1;
 
-        if (VIR_REALLOC_N_QUIET(buf, need + 1) < 0)
-            goto cleanup;
+        buf = g_renew(char, buf, need + 1);
 
         if ((got = getxattr(path, name, buf, need)) < 0) {
             if (errno == ERANGE)
                 continue;
-            goto cleanup;
+            return -1;
         }
 
         buf[got] = '\0';
@@ -4353,10 +4351,7 @@ virFileGetXAttrQuiet(const char *path,
     }
 
     *value = g_steal_pointer(&buf);
-    ret = 0;
- cleanup:
-    VIR_FREE(buf);
-    return ret;
+    return 0;
 }
 
 /**
-- 
2.26.2




[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