Blob Blame History Raw
From 6d7049a19029331266f70f68d860bbccef01a35d Mon Sep 17 00:00:00 2001
From: Nikhil Ladha <nladha@redhat.com>
Date: Thu, 8 Jul 2021 11:26:54 +0530
Subject: [PATCH 601/610] coverity: resource leak (#2321)

Issue:
Variable `arg` is not freed before the function exits,
and leads to resource leak.

Fix:
Free the arg variable if the status of function call
`glusterd_compare_friend_volume` is
`GLUSTERD_VOL_COMP_UPDATE_REQ`, or if the `glusterd_launch_synctask`
fails to start the process.

And, added a check for return value on calling
`glusterd_launch_synctask` function and exit if the
thread creation fails.

CID: 1401716
>Updates: #1060

>Change-Id: I4abd621771f88853d8d01e9039cdee2f3d862c4f
>Signed-off-by: nik-redhat <nladha@redhat.com>

Upstream link: https://github.com/gluster/glusterfs/pull/2321
BUG: 1997447

Change-Id: Ida81dfcd58c5ef45d3ae036d6bd6b36dc6693538
Signed-off-by: nik-redhat <nladha@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/c/rhs-glusterfs/+/280090
Tested-by: RHGS Build Bot <nigelb@redhat.com>
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
---
 xlators/mgmt/glusterd/src/glusterd-utils.c | 10 +++++++---
 xlators/mgmt/glusterd/src/glusterd-utils.h |  2 +-
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
index c037933..cec9c20 100644
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
@@ -5371,6 +5371,7 @@ glusterd_compare_friend_data(dict_t *peer_data, dict_t *cmp, int32_t *status,
 
         if (GLUSTERD_VOL_COMP_RJT == *status) {
             ret = 0;
+            update = _gf_false;
             goto out;
         }
         if (GLUSTERD_VOL_COMP_UPDATE_REQ == *status) {
@@ -5385,11 +5386,12 @@ glusterd_compare_friend_data(dict_t *peer_data, dict_t *cmp, int32_t *status,
          * first brick to come up before attaching the subsequent bricks
          * in case brick multiplexing is enabled
          */
-        glusterd_launch_synctask(glusterd_import_friend_volumes_synctask, arg);
+        ret = glusterd_launch_synctask(glusterd_import_friend_volumes_synctask,
+                                       arg);
     }
 
 out:
-    if (ret && arg) {
+    if ((ret || !update) && arg) {
         dict_unref(arg->peer_data);
         dict_unref(arg->peer_ver_data);
         GF_FREE(arg);
@@ -13115,7 +13117,7 @@ gd_default_synctask_cbk(int ret, call_frame_t *frame, void *opaque)
     return ret;
 }
 
-void
+int
 glusterd_launch_synctask(synctask_fn_t fn, void *opaque)
 {
     xlator_t *this = NULL;
@@ -13131,6 +13133,8 @@ glusterd_launch_synctask(synctask_fn_t fn, void *opaque)
         gf_msg(this->name, GF_LOG_CRITICAL, 0, GD_MSG_SPAWN_SVCS_FAIL,
                "Failed to spawn bricks"
                " and other volume related services");
+
+    return ret;
 }
 
 /*
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.h b/xlators/mgmt/glusterd/src/glusterd-utils.h
index 4541471..3f4f3b8 100644
--- a/xlators/mgmt/glusterd/src/glusterd-utils.h
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.h
@@ -681,7 +681,7 @@ int32_t
 glusterd_take_lvm_snapshot(glusterd_brickinfo_t *brickinfo,
                            char *origin_brick_path);
 
-void
+int
 glusterd_launch_synctask(synctask_fn_t fn, void *opaque);
 
 int
-- 
1.8.3.1