mirror of https://gitee.com/openkylin/libvirt.git
security: use g_new0 instead of VIR_ALLOC*
Signed-off-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
This commit is contained in:
parent
366ca7efbe
commit
f67be086a2
|
@ -867,8 +867,7 @@ AppArmorSetSecurityHostdevLabel(virSecurityManagerPtr mgr,
|
|||
if (profile_loaded(secdef->imagelabel) < 0)
|
||||
return 0;
|
||||
|
||||
if (VIR_ALLOC(ptr) < 0)
|
||||
return -1;
|
||||
ptr = g_new0(struct SDPDOP, 1);
|
||||
ptr->mgr = mgr;
|
||||
ptr->def = def;
|
||||
|
||||
|
|
|
@ -108,8 +108,7 @@ virSecurityDACChownListAppend(virSecurityDACChownListPtr list,
|
|||
char *tmp = NULL;
|
||||
virSecurityDACChownItemPtr item = NULL;
|
||||
|
||||
if (VIR_ALLOC(item) < 0)
|
||||
return -1;
|
||||
item = g_new0(virSecurityDACChownItem, 1);
|
||||
|
||||
tmp = g_strdup(path);
|
||||
|
||||
|
@ -227,8 +226,7 @@ virSecurityDACTransactionRun(pid_t pid G_GNUC_UNUSED,
|
|||
int ret = -1;
|
||||
|
||||
if (list->lock) {
|
||||
if (VIR_ALLOC_N(paths, list->nItems) < 0)
|
||||
return -1;
|
||||
paths = g_new0(const char *, list->nItems);
|
||||
|
||||
for (i = 0; i < list->nItems; i++) {
|
||||
virSecurityDACChownItemPtr item = list->items[i];
|
||||
|
@ -580,8 +578,7 @@ virSecurityDACTransactionStart(virSecurityManagerPtr mgr)
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (VIR_ALLOC(list) < 0)
|
||||
return -1;
|
||||
list = g_new0(virSecurityDACChownList, 1);
|
||||
|
||||
list->manager = virObjectRef(mgr);
|
||||
|
||||
|
|
|
@ -87,8 +87,7 @@ virSecurityManagerNewDriver(virSecurityDriverPtr drv,
|
|||
|
||||
virCheckFlags(VIR_SECURITY_MANAGER_NEW_MASK, NULL);
|
||||
|
||||
if (VIR_ALLOC_N(privateData, drv->privateDataLen) < 0)
|
||||
return NULL;
|
||||
privateData = g_new0(char, drv->privateDataLen);
|
||||
|
||||
if (!(mgr = virObjectLockableNew(virSecurityManagerClass)))
|
||||
goto error;
|
||||
|
@ -1034,8 +1033,7 @@ virSecurityManagerGetNested(virSecurityManagerPtr mgr)
|
|||
if (STREQ("stack", mgr->drv->name))
|
||||
return virSecurityStackGetNested(mgr);
|
||||
|
||||
if (VIR_ALLOC_N(list, 2) < 0)
|
||||
return NULL;
|
||||
list = g_new0(virSecurityManagerPtr, 2);
|
||||
|
||||
list[0] = mgr;
|
||||
list[1] = NULL;
|
||||
|
@ -1346,9 +1344,8 @@ virSecurityManagerMetadataLock(virSecurityManagerPtr mgr G_GNUC_UNUSED,
|
|||
const char **locked_paths = NULL;
|
||||
virSecurityManagerMetadataLockStatePtr ret = NULL;
|
||||
|
||||
if (VIR_ALLOC_N(fds, npaths) < 0 ||
|
||||
VIR_ALLOC_N(locked_paths, npaths) < 0)
|
||||
return NULL;
|
||||
fds = g_new0(int, npaths);
|
||||
locked_paths = g_new0(const char *, npaths);
|
||||
|
||||
/* Sort paths to lock in order to avoid deadlocks with other
|
||||
* processes. For instance, if one process wants to lock
|
||||
|
@ -1441,8 +1438,7 @@ virSecurityManagerMetadataLock(virSecurityManagerPtr mgr G_GNUC_UNUSED,
|
|||
VIR_APPEND_ELEMENT_COPY_INPLACE(fds, nfds, fd);
|
||||
}
|
||||
|
||||
if (VIR_ALLOC(ret) < 0)
|
||||
goto cleanup;
|
||||
ret = g_new0(virSecurityManagerMetadataLockState, 1);
|
||||
|
||||
ret->paths = g_steal_pointer(&locked_paths);
|
||||
ret->fds = g_steal_pointer(&fds);
|
||||
|
|
|
@ -123,8 +123,7 @@ virSecuritySELinuxContextListAppend(virSecuritySELinuxContextListPtr list,
|
|||
int ret = -1;
|
||||
virSecuritySELinuxContextItemPtr item = NULL;
|
||||
|
||||
if (VIR_ALLOC(item) < 0)
|
||||
return -1;
|
||||
item = g_new0(virSecuritySELinuxContextItem, 1);
|
||||
|
||||
item->path = g_strdup(path);
|
||||
item->tcon = g_strdup(tcon);
|
||||
|
@ -258,8 +257,7 @@ virSecuritySELinuxTransactionRun(pid_t pid G_GNUC_UNUSED,
|
|||
int ret = -1;
|
||||
|
||||
if (list->lock) {
|
||||
if (VIR_ALLOC_N(paths, list->nItems) < 0)
|
||||
return -1;
|
||||
paths = g_new0(const char *, list->nItems);
|
||||
|
||||
for (i = 0; i < list->nItems; i++) {
|
||||
virSecuritySELinuxContextItemPtr item = list->items[i];
|
||||
|
@ -1088,8 +1086,7 @@ virSecuritySELinuxTransactionStart(virSecurityManagerPtr mgr)
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (VIR_ALLOC(list) < 0)
|
||||
return -1;
|
||||
list = g_new0(virSecuritySELinuxContextList, 1);
|
||||
|
||||
list->manager = virObjectRef(mgr);
|
||||
|
||||
|
|
|
@ -56,8 +56,7 @@ virSecurityStackAddNested(virSecurityManagerPtr mgr,
|
|||
while (tmp && tmp->next)
|
||||
tmp = tmp->next;
|
||||
|
||||
if (VIR_ALLOC(item) < 0)
|
||||
return -1;
|
||||
item = g_new0(virSecurityStackItem, 1);
|
||||
item->securityManager = nested;
|
||||
item->prev = tmp;
|
||||
if (tmp)
|
||||
|
@ -620,8 +619,7 @@ virSecurityStackGetNested(virSecurityManagerPtr mgr)
|
|||
for (item = priv->itemsHead; item; item = item->next)
|
||||
len++;
|
||||
|
||||
if (VIR_ALLOC_N(list, len + 1) < 0)
|
||||
return NULL;
|
||||
list = g_new0(virSecurityManagerPtr, len + 1);
|
||||
|
||||
for (i = 0, item = priv->itemsHead; item; item = item->next, i++)
|
||||
list[i] = item->securityManager;
|
||||
|
|
Loading…
Reference in New Issue