[libvirt PATCH 09/13] conf: virsecretobj: use g_new0

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

 



Signed-off-by: Ján Tomko <jtomko@xxxxxxxxxx>
---
 src/conf/virsecretobj.c | 21 ++++++---------------
 1 file changed, 6 insertions(+), 15 deletions(-)

diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c
index 81c9f2c346..c98d52f1e4 100644
--- a/src/conf/virsecretobj.c
+++ b/src/conf/virsecretobj.c
@@ -465,10 +465,7 @@ virSecretObjListGetUUIDsCallback(void *payload,
     if (data->uuids) {
         char *uuidstr;
 
-        if (VIR_ALLOC_N(uuidstr, VIR_UUID_STRING_BUFLEN) < 0) {
-            data->error = true;
-            goto cleanup;
-        }
+        uuidstr = g_new0(char, VIR_UUID_STRING_BUFLEN);
 
         virUUIDFormat(def->uuid, uuidstr);
         data->uuids[data->nuuids++] = uuidstr;
@@ -590,11 +587,8 @@ virSecretObjListExport(virConnectPtr conn,
         .nsecrets = 0, .error = false };
 
     virObjectRWLockRead(secretobjs);
-    if (secrets &&
-        VIR_ALLOC_N(data.secrets, virHashSize(secretobjs->objs) + 1) < 0) {
-        virObjectRWUnlock(secretobjs);
-        return -1;
-    }
+    if (secrets)
+        data.secrets = g_new0(virSecretPtr, virHashSize(secretobjs->objs));
 
     virHashForEach(secretobjs->objs, virSecretObjListExportCallback, &data);
     virObjectRWUnlock(secretobjs);
@@ -735,8 +729,7 @@ virSecretObjGetValue(virSecretObjPtr obj)
         return NULL;
     }
 
-    if (VIR_ALLOC_N(ret, obj->value_size) < 0)
-        return NULL;
+    ret = g_new0(unsigned char, obj->value_size);
     memcpy(ret, obj->value, obj->value_size);
 
     return ret;
@@ -753,8 +746,7 @@ virSecretObjSetValue(virSecretObjPtr obj,
     g_autofree unsigned char *new_value = NULL;
     size_t old_value_size;
 
-    if (VIR_ALLOC_N(new_value, value_size) < 0)
-        return -1;
+    new_value = g_new0(unsigned char, value_size);
 
     old_value = obj->value;
     old_value_size = obj->value_size;
@@ -846,8 +838,7 @@ virSecretLoadValue(virSecretObjPtr obj)
         goto cleanup;
     }
 
-    if (VIR_ALLOC_N(contents, st.st_size + 1) < 0)
-        goto cleanup;
+    contents = g_new0(char, st.st_size + 1);
 
     if (saferead(fd, contents, st.st_size) != st.st_size) {
         virReportSystemError(errno, _("cannot read '%s'"),
-- 
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