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

Re: [libvirt PATCH 4/5] security: use g_new0 instead of VIR_ALLOC*





On 9/23/20 5:11 PM, Ján Tomko wrote:
Signed-off-by: Ján Tomko <jtomko redhat com>
---

Reviewed-by: Daniel Henrique Barboza <danielhb413 gmail com>

  src/security/security_apparmor.c |  3 +--
  src/security/security_dac.c      |  9 +++------
  src/security/security_manager.c  | 14 +++++---------
  src/security/security_selinux.c  |  9 +++------
  src/security/security_stack.c    |  6 ++----
  5 files changed, 14 insertions(+), 27 deletions(-)

diff --git a/src/security/security_apparmor.c b/src/security/security_apparmor.c
index eea37dca83..c2d86c6940 100644
--- a/src/security/security_apparmor.c
+++ b/src/security/security_apparmor.c
@@ -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;
diff --git a/src/security/security_dac.c b/src/security/security_dac.c
index d9d4cda159..258d246659 100644
--- a/src/security/security_dac.c
+++ b/src/security/security_dac.c
@@ -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); diff --git a/src/security/security_manager.c b/src/security/security_manager.c
index 17b565cc12..be81ee5e44 100644
--- a/src/security/security_manager.c
+++ b/src/security/security_manager.c
@@ -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);
diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c
index 87741d6dad..e40d670e97 100644
--- a/src/security/security_selinux.c
+++ b/src/security/security_selinux.c
@@ -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); diff --git a/src/security/security_stack.c b/src/security/security_stack.c
index 2480c47f70..3bfcb1e2f7 100644
--- a/src/security/security_stack.c
+++ b/src/security/security_stack.c
@@ -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;



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