c460ee
From 6d7049a19029331266f70f68d860bbccef01a35d Mon Sep 17 00:00:00 2001
c460ee
From: Nikhil Ladha <nladha@redhat.com>
c460ee
Date: Thu, 8 Jul 2021 11:26:54 +0530
c460ee
Subject: [PATCH 601/610] coverity: resource leak (#2321)
c460ee
c460ee
Issue:
c460ee
Variable `arg` is not freed before the function exits,
c460ee
and leads to resource leak.
c460ee
c460ee
Fix:
c460ee
Free the arg variable if the status of function call
c460ee
`glusterd_compare_friend_volume` is
c460ee
`GLUSTERD_VOL_COMP_UPDATE_REQ`, or if the `glusterd_launch_synctask`
c460ee
fails to start the process.
c460ee
c460ee
And, added a check for return value on calling
c460ee
`glusterd_launch_synctask` function and exit if the
c460ee
thread creation fails.
c460ee
c460ee
CID: 1401716
c460ee
>Updates: #1060
c460ee
c460ee
>Change-Id: I4abd621771f88853d8d01e9039cdee2f3d862c4f
c460ee
>Signed-off-by: nik-redhat <nladha@redhat.com>
c460ee
c460ee
Upstream link: https://github.com/gluster/glusterfs/pull/2321
c460ee
BUG: 1997447
c460ee
c460ee
Change-Id: Ida81dfcd58c5ef45d3ae036d6bd6b36dc6693538
c460ee
Signed-off-by: nik-redhat <nladha@redhat.com>
c460ee
Reviewed-on: https://code.engineering.redhat.com/gerrit/c/rhs-glusterfs/+/280090
c460ee
Tested-by: RHGS Build Bot <nigelb@redhat.com>
c460ee
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
c460ee
---
c460ee
 xlators/mgmt/glusterd/src/glusterd-utils.c | 10 +++++++---
c460ee
 xlators/mgmt/glusterd/src/glusterd-utils.h |  2 +-
c460ee
 2 files changed, 8 insertions(+), 4 deletions(-)
c460ee
c460ee
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
c460ee
index c037933..cec9c20 100644
c460ee
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
c460ee
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
c460ee
@@ -5371,6 +5371,7 @@ glusterd_compare_friend_data(dict_t *peer_data, dict_t *cmp, int32_t *status,
c460ee
 
c460ee
         if (GLUSTERD_VOL_COMP_RJT == *status) {
c460ee
             ret = 0;
c460ee
+            update = _gf_false;
c460ee
             goto out;
c460ee
         }
c460ee
         if (GLUSTERD_VOL_COMP_UPDATE_REQ == *status) {
c460ee
@@ -5385,11 +5386,12 @@ glusterd_compare_friend_data(dict_t *peer_data, dict_t *cmp, int32_t *status,
c460ee
          * first brick to come up before attaching the subsequent bricks
c460ee
          * in case brick multiplexing is enabled
c460ee
          */
c460ee
-        glusterd_launch_synctask(glusterd_import_friend_volumes_synctask, arg);
c460ee
+        ret = glusterd_launch_synctask(glusterd_import_friend_volumes_synctask,
c460ee
+                                       arg);
c460ee
     }
c460ee
 
c460ee
 out:
c460ee
-    if (ret && arg) {
c460ee
+    if ((ret || !update) && arg) {
c460ee
         dict_unref(arg->peer_data);
c460ee
         dict_unref(arg->peer_ver_data);
c460ee
         GF_FREE(arg);
c460ee
@@ -13115,7 +13117,7 @@ gd_default_synctask_cbk(int ret, call_frame_t *frame, void *opaque)
c460ee
     return ret;
c460ee
 }
c460ee
 
c460ee
-void
c460ee
+int
c460ee
 glusterd_launch_synctask(synctask_fn_t fn, void *opaque)
c460ee
 {
c460ee
     xlator_t *this = NULL;
c460ee
@@ -13131,6 +13133,8 @@ glusterd_launch_synctask(synctask_fn_t fn, void *opaque)
c460ee
         gf_msg(this->name, GF_LOG_CRITICAL, 0, GD_MSG_SPAWN_SVCS_FAIL,
c460ee
                "Failed to spawn bricks"
c460ee
                " and other volume related services");
c460ee
+
c460ee
+    return ret;
c460ee
 }
c460ee
 
c460ee
 /*
c460ee
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.h b/xlators/mgmt/glusterd/src/glusterd-utils.h
c460ee
index 4541471..3f4f3b8 100644
c460ee
--- a/xlators/mgmt/glusterd/src/glusterd-utils.h
c460ee
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.h
c460ee
@@ -681,7 +681,7 @@ int32_t
c460ee
 glusterd_take_lvm_snapshot(glusterd_brickinfo_t *brickinfo,
c460ee
                            char *origin_brick_path);
c460ee
 
c460ee
-void
c460ee
+int
c460ee
 glusterd_launch_synctask(synctask_fn_t fn, void *opaque);
c460ee
 
c460ee
 int
c460ee
-- 
c460ee
1.8.3.1
c460ee