conf: virsecretobj: use g_new0

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Neal Gompa <ngompa13@gmail.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
Ján Tomko 2020-10-07 21:15:03 +02:00
parent cbe919915e
commit d5b05614df

View File

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