74096c
From 179213798496448316547506da65dbd9fd741dfa Mon Sep 17 00:00:00 2001
74096c
From: Atin Mukherjee <amukherj@redhat.com>
74096c
Date: Wed, 24 Apr 2019 22:02:51 +0530
74096c
Subject: [PATCH 436/449] glusterd: coverity fixes
74096c
74096c
Addresses the following:
74096c
74096c
* CID 1124776:  Resource leaks  (RESOURCE_LEAK) - Variable "aa" going out
74096c
of scope leaks the storage it points to in glusterd-volgen.c
74096c
74096c
* Bunch of CHECKED_RETURN defects in the callers of synctask_barrier_init
74096c
74096c
* CID 1400742:  Program hangs  (LOCK) - adding annotation to fix this
74096c
false positive
74096c
74096c
> upstream patch link: https://review.gluster.org/#/c/glusterfs/+/22615
74096c
> Updates: bz#789278
74096c
> Change-Id: I02f16e7eeb8c5cf72f7d0b29d00df4f03b3718b3
74096c
> Signed-off-by: Atin Mukherjee <amukherj@redhat.com>
74096c
74096c
BUG: 1787310
74096c
Change-Id: I02f16e7eeb8c5cf72f7d0b29d00df4f03b3718b3
74096c
Signed-off-by: Sanju Rakonde <srakonde@redhat.com>
74096c
Reviewed-on: https://code.engineering.redhat.com/gerrit/202626
74096c
Tested-by: RHGS Build Bot <nigelb@redhat.com>
74096c
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
74096c
---
74096c
 xlators/mgmt/glusterd/src/glusterd-handler.c |  6 ++++++
74096c
 xlators/mgmt/glusterd/src/glusterd-mgmt.c    | 24 +++++++++++++++++++-----
74096c
 xlators/mgmt/glusterd/src/glusterd-syncop.c  | 22 ++++++++++++++++++----
74096c
 xlators/mgmt/glusterd/src/glusterd-volgen.c  |  5 +++--
74096c
 4 files changed, 46 insertions(+), 11 deletions(-)
74096c
74096c
diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c
74096c
index 1f31e72..b8799ab 100644
74096c
--- a/xlators/mgmt/glusterd/src/glusterd-handler.c
74096c
+++ b/xlators/mgmt/glusterd/src/glusterd-handler.c
74096c
@@ -3458,6 +3458,12 @@ glusterd_friend_remove(uuid_t uuid, char *hostname)
74096c
     ret = glusterd_peerinfo_cleanup(peerinfo);
74096c
 out:
74096c
     gf_msg_debug(THIS->name, 0, "returning %d", ret);
74096c
+    /* We don't need to do a mutex unlock of peerinfo->delete_lock as the same
74096c
+     * will be anyway destroyed within glusterd_peerinfo_cleanup, coverity
74096c
+     * though cries about it
74096c
+     */
74096c
+    /* coverity[LOCK] */
74096c
+
74096c
     return ret;
74096c
 }
74096c
 
74096c
diff --git a/xlators/mgmt/glusterd/src/glusterd-mgmt.c b/xlators/mgmt/glusterd/src/glusterd-mgmt.c
74096c
index a4915f3..1e185d7 100644
74096c
--- a/xlators/mgmt/glusterd/src/glusterd-mgmt.c
74096c
+++ b/xlators/mgmt/glusterd/src/glusterd-mgmt.c
74096c
@@ -757,7 +757,10 @@ glusterd_mgmt_v3_initiate_lockdown(glusterd_op_t op, dict_t *dict,
74096c
 
74096c
     /* Sending mgmt_v3 lock req to other nodes in the cluster */
74096c
     gd_syncargs_init(&args, NULL);
74096c
-    synctask_barrier_init((&args));
74096c
+    ret = synctask_barrier_init((&args));
74096c
+    if (ret)
74096c
+        goto out;
74096c
+
74096c
     peer_cnt = 0;
74096c
 
74096c
     RCU_READ_LOCK;
74096c
@@ -1108,7 +1111,10 @@ glusterd_mgmt_v3_pre_validate(glusterd_op_t op, dict_t *req_dict,
74096c
 
74096c
     /* Sending Pre Validation req to other nodes in the cluster */
74096c
     gd_syncargs_init(&args, req_dict);
74096c
-    synctask_barrier_init((&args));
74096c
+    ret = synctask_barrier_init((&args));
74096c
+    if (ret)
74096c
+        goto out;
74096c
+
74096c
     peer_cnt = 0;
74096c
 
74096c
     RCU_READ_LOCK;
74096c
@@ -1458,7 +1464,10 @@ glusterd_mgmt_v3_brick_op(glusterd_op_t op, dict_t *op_ctx, dict_t *req_dict,
74096c
 
74096c
     /* Sending brick op req to other nodes in the cluster */
74096c
     gd_syncargs_init(&args, op_ctx);
74096c
-    synctask_barrier_init((&args));
74096c
+    ret = synctask_barrier_init((&args));
74096c
+    if (ret)
74096c
+        goto out;
74096c
+
74096c
     peer_cnt = 0;
74096c
 
74096c
     RCU_READ_LOCK;
74096c
@@ -1722,7 +1731,9 @@ glusterd_mgmt_v3_commit(glusterd_op_t op, dict_t *op_ctx, dict_t *req_dict,
74096c
 
74096c
     /* Sending commit req to other nodes in the cluster */
74096c
     gd_syncargs_init(&args, op_ctx);
74096c
-    synctask_barrier_init((&args));
74096c
+    ret = synctask_barrier_init((&args));
74096c
+    if (ret)
74096c
+        goto out;
74096c
     peer_cnt = 0;
74096c
 
74096c
     RCU_READ_LOCK;
74096c
@@ -1963,7 +1974,10 @@ glusterd_mgmt_v3_post_validate(glusterd_op_t op, int32_t op_ret, dict_t *dict,
74096c
 
74096c
     /* Sending Post Validation req to other nodes in the cluster */
74096c
     gd_syncargs_init(&args, req_dict);
74096c
-    synctask_barrier_init((&args));
74096c
+    ret = synctask_barrier_init((&args));
74096c
+    if (ret)
74096c
+        goto out;
74096c
+
74096c
     peer_cnt = 0;
74096c
 
74096c
     RCU_READ_LOCK;
74096c
diff --git a/xlators/mgmt/glusterd/src/glusterd-syncop.c b/xlators/mgmt/glusterd/src/glusterd-syncop.c
74096c
index 9e47d14..c78983a 100644
74096c
--- a/xlators/mgmt/glusterd/src/glusterd-syncop.c
74096c
+++ b/xlators/mgmt/glusterd/src/glusterd-syncop.c
74096c
@@ -1191,7 +1191,12 @@ gd_lock_op_phase(glusterd_conf_t *conf, glusterd_op_t op, dict_t *op_ctx,
74096c
     struct syncargs args = {0};
74096c
 
74096c
     this = THIS;
74096c
-    synctask_barrier_init((&args));
74096c
+    GF_VALIDATE_OR_GOTO("glusterd", this, out);
74096c
+
74096c
+    ret = synctask_barrier_init((&args));
74096c
+    if (ret)
74096c
+        goto out;
74096c
+
74096c
     peer_cnt = 0;
74096c
 
74096c
     RCU_READ_LOCK;
74096c
@@ -1321,7 +1326,10 @@ stage_done:
74096c
     }
74096c
 
74096c
     gd_syncargs_init(&args, aggr_dict);
74096c
-    synctask_barrier_init((&args));
74096c
+    ret = synctask_barrier_init((&args));
74096c
+    if (ret)
74096c
+        goto out;
74096c
+
74096c
     peer_cnt = 0;
74096c
 
74096c
     RCU_READ_LOCK;
74096c
@@ -1449,7 +1457,10 @@ commit_done:
74096c
     }
74096c
 
74096c
     gd_syncargs_init(&args, op_ctx);
74096c
-    synctask_barrier_init((&args));
74096c
+    ret = synctask_barrier_init((&args));
74096c
+    if (ret)
74096c
+        goto out;
74096c
+
74096c
     peer_cnt = 0;
74096c
     origin_glusterd = is_origin_glusterd(req_dict);
74096c
 
74096c
@@ -1541,7 +1552,10 @@ gd_unlock_op_phase(glusterd_conf_t *conf, glusterd_op_t op, int *op_ret,
74096c
         goto out;
74096c
     }
74096c
 
74096c
-    synctask_barrier_init((&args));
74096c
+    ret = synctask_barrier_init((&args));
74096c
+    if (ret)
74096c
+        goto out;
74096c
+
74096c
     peer_cnt = 0;
74096c
 
74096c
     if (cluster_lock) {
74096c
diff --git a/xlators/mgmt/glusterd/src/glusterd-volgen.c b/xlators/mgmt/glusterd/src/glusterd-volgen.c
74096c
index 6852f8e..16346e7 100644
74096c
--- a/xlators/mgmt/glusterd/src/glusterd-volgen.c
74096c
+++ b/xlators/mgmt/glusterd/src/glusterd-volgen.c
74096c
@@ -4808,9 +4808,10 @@ nfs_option_handler(volgen_graph_t *graph, struct volopt_map_entry *vme,
74096c
 
74096c
         if (ret != -1) {
74096c
             ret = gf_canonicalize_path(vme->value);
74096c
-            if (ret)
74096c
+            if (ret) {
74096c
+                GF_FREE(aa);
74096c
                 return -1;
74096c
-
74096c
+            }
74096c
             ret = xlator_set_option(xl, aa, ret, vme->value);
74096c
             GF_FREE(aa);
74096c
         }
74096c
-- 
74096c
1.8.3.1
74096c