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:
Ján Tomko 2020-09-23 22:05:21 +02:00
parent 366ca7efbe
commit f67be086a2
5 changed files with 14 additions and 27 deletions

View File

@ -867,8 +867,7 @@ AppArmorSetSecurityHostdevLabel(virSecurityManagerPtr mgr,
if (profile_loaded(secdef->imagelabel) < 0) if (profile_loaded(secdef->imagelabel) < 0)
return 0; return 0;
if (VIR_ALLOC(ptr) < 0) ptr = g_new0(struct SDPDOP, 1);
return -1;
ptr->mgr = mgr; ptr->mgr = mgr;
ptr->def = def; ptr->def = def;

View File

@ -108,8 +108,7 @@ virSecurityDACChownListAppend(virSecurityDACChownListPtr list,
char *tmp = NULL; char *tmp = NULL;
virSecurityDACChownItemPtr item = NULL; virSecurityDACChownItemPtr item = NULL;
if (VIR_ALLOC(item) < 0) item = g_new0(virSecurityDACChownItem, 1);
return -1;
tmp = g_strdup(path); tmp = g_strdup(path);
@ -227,8 +226,7 @@ virSecurityDACTransactionRun(pid_t pid G_GNUC_UNUSED,
int ret = -1; int ret = -1;
if (list->lock) { if (list->lock) {
if (VIR_ALLOC_N(paths, list->nItems) < 0) paths = g_new0(const char *, list->nItems);
return -1;
for (i = 0; i < list->nItems; i++) { for (i = 0; i < list->nItems; i++) {
virSecurityDACChownItemPtr item = list->items[i]; virSecurityDACChownItemPtr item = list->items[i];
@ -580,8 +578,7 @@ virSecurityDACTransactionStart(virSecurityManagerPtr mgr)
return -1; return -1;
} }
if (VIR_ALLOC(list) < 0) list = g_new0(virSecurityDACChownList, 1);
return -1;
list->manager = virObjectRef(mgr); list->manager = virObjectRef(mgr);

View File

@ -87,8 +87,7 @@ virSecurityManagerNewDriver(virSecurityDriverPtr drv,
virCheckFlags(VIR_SECURITY_MANAGER_NEW_MASK, NULL); virCheckFlags(VIR_SECURITY_MANAGER_NEW_MASK, NULL);
if (VIR_ALLOC_N(privateData, drv->privateDataLen) < 0) privateData = g_new0(char, drv->privateDataLen);
return NULL;
if (!(mgr = virObjectLockableNew(virSecurityManagerClass))) if (!(mgr = virObjectLockableNew(virSecurityManagerClass)))
goto error; goto error;
@ -1034,8 +1033,7 @@ virSecurityManagerGetNested(virSecurityManagerPtr mgr)
if (STREQ("stack", mgr->drv->name)) if (STREQ("stack", mgr->drv->name))
return virSecurityStackGetNested(mgr); return virSecurityStackGetNested(mgr);
if (VIR_ALLOC_N(list, 2) < 0) list = g_new0(virSecurityManagerPtr, 2);
return NULL;
list[0] = mgr; list[0] = mgr;
list[1] = NULL; list[1] = NULL;
@ -1346,9 +1344,8 @@ virSecurityManagerMetadataLock(virSecurityManagerPtr mgr G_GNUC_UNUSED,
const char **locked_paths = NULL; const char **locked_paths = NULL;
virSecurityManagerMetadataLockStatePtr ret = NULL; virSecurityManagerMetadataLockStatePtr ret = NULL;
if (VIR_ALLOC_N(fds, npaths) < 0 || fds = g_new0(int, npaths);
VIR_ALLOC_N(locked_paths, npaths) < 0) locked_paths = g_new0(const char *, npaths);
return NULL;
/* Sort paths to lock in order to avoid deadlocks with other /* Sort paths to lock in order to avoid deadlocks with other
* processes. For instance, if one process wants to lock * 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); VIR_APPEND_ELEMENT_COPY_INPLACE(fds, nfds, fd);
} }
if (VIR_ALLOC(ret) < 0) ret = g_new0(virSecurityManagerMetadataLockState, 1);
goto cleanup;
ret->paths = g_steal_pointer(&locked_paths); ret->paths = g_steal_pointer(&locked_paths);
ret->fds = g_steal_pointer(&fds); ret->fds = g_steal_pointer(&fds);

View File

@ -123,8 +123,7 @@ virSecuritySELinuxContextListAppend(virSecuritySELinuxContextListPtr list,
int ret = -1; int ret = -1;
virSecuritySELinuxContextItemPtr item = NULL; virSecuritySELinuxContextItemPtr item = NULL;
if (VIR_ALLOC(item) < 0) item = g_new0(virSecuritySELinuxContextItem, 1);
return -1;
item->path = g_strdup(path); item->path = g_strdup(path);
item->tcon = g_strdup(tcon); item->tcon = g_strdup(tcon);
@ -258,8 +257,7 @@ virSecuritySELinuxTransactionRun(pid_t pid G_GNUC_UNUSED,
int ret = -1; int ret = -1;
if (list->lock) { if (list->lock) {
if (VIR_ALLOC_N(paths, list->nItems) < 0) paths = g_new0(const char *, list->nItems);
return -1;
for (i = 0; i < list->nItems; i++) { for (i = 0; i < list->nItems; i++) {
virSecuritySELinuxContextItemPtr item = list->items[i]; virSecuritySELinuxContextItemPtr item = list->items[i];
@ -1088,8 +1086,7 @@ virSecuritySELinuxTransactionStart(virSecurityManagerPtr mgr)
return -1; return -1;
} }
if (VIR_ALLOC(list) < 0) list = g_new0(virSecuritySELinuxContextList, 1);
return -1;
list->manager = virObjectRef(mgr); list->manager = virObjectRef(mgr);

View File

@ -56,8 +56,7 @@ virSecurityStackAddNested(virSecurityManagerPtr mgr,
while (tmp && tmp->next) while (tmp && tmp->next)
tmp = tmp->next; tmp = tmp->next;
if (VIR_ALLOC(item) < 0) item = g_new0(virSecurityStackItem, 1);
return -1;
item->securityManager = nested; item->securityManager = nested;
item->prev = tmp; item->prev = tmp;
if (tmp) if (tmp)
@ -620,8 +619,7 @@ virSecurityStackGetNested(virSecurityManagerPtr mgr)
for (item = priv->itemsHead; item; item = item->next) for (item = priv->itemsHead; item; item = item->next)
len++; len++;
if (VIR_ALLOC_N(list, len + 1) < 0) list = g_new0(virSecurityManagerPtr, len + 1);
return NULL;
for (i = 0, item = priv->itemsHead; item; item = item->next, i++) for (i = 0, item = priv->itemsHead; item; item = item->next, i++)
list[i] = item->securityManager; list[i] = item->securityManager;