Blob Blame History Raw
From ff98fc7a53b51b14c64c47def854d98cbd1f3ca0 Mon Sep 17 00:00:00 2001
From: Mohit Agrawal <moagrawa@redhat.com>
Date: Mon, 21 Jan 2019 20:52:36 +0530
Subject: [PATCH 508/508] glusterd: Resolve multiple leaks in glusterd code
 path

In gluster get-state volumeoptions command there was some amount of leak
observed. This fix resolves the identified leaks.

> Change-Id: Ibde5743d1136fa72c531d48bb1b0b5da0c0b82a1
> fixes: bz#1667779
> (Cherry picked from commit 5903111ad21cb937258c0fda24ea7dec466347b4)
> (Cherry picked from commit 4d3be307293b63c74398dfa715e9920cf356f083)
> (Cherry picked from commit 2b7b6ff28fa92335613d0b5715acd552cfcfd759)
> (Reviewed on upstream link https://review.gluster.org/#/c/glusterfs/+/21823/)
> (Reviewed on upstream link https://review.gluster.org/#/c/glusterfs/+/20888/)
> (Reviewed on upstream link https://review.gluster.org/#/c/glusterfs/+/22064/)

Change-Id: I7bf3ed61770511c73975ad7b0d4fe97619c9864a
BUG: 1667169
Signed-off-by: Mohit Agrawal <moagrawa@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/161128
Tested-by: RHGS Build Bot <nigelb@redhat.com>
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
---
 xlators/mgmt/glusterd/src/glusterd-handler.c | 13 ++++++++++---
 xlators/mgmt/glusterd/src/glusterd-utils.c   | 11 +++++++++++
 2 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c
index d8e333510..81b1c029d 100644
--- a/xlators/mgmt/glusterd/src/glusterd-handler.c
+++ b/xlators/mgmt/glusterd/src/glusterd-handler.c
@@ -1808,6 +1808,8 @@ out:
         glusterd_to_cli (req, &rsp, NULL, 0, NULL,
                          (xdrproc_t)xdr_gf_cli_rsp, dict);
 
+        GF_FREE(rsp.dict.dict_val);
+
         return 0;
 }
 int
@@ -1871,6 +1873,7 @@ out:
         if (dict)
                 dict_unref (dict);
 
+        GF_FREE(rsp.dict.dict_val);
         glusterd_friend_sm ();
         glusterd_op_sm ();
 
@@ -4991,6 +4994,7 @@ out:
 
         glusterd_submit_reply (req, &rsp, NULL, 0, NULL,
                                (xdrproc_t)xdr_gf_cli_rsp);
+        GF_FREE(rsp.dict.dict_val);
         return ret;
 }
 
@@ -5221,7 +5225,7 @@ glusterd_print_snapinfo_by_vol (FILE *fp, glusterd_volinfo_t *volinfo, int volco
                 fprintf (fp, "Volume%d.snapshot%d.name: %s\n",
                          volcount, snapcount, snapinfo->snapname);
                 fprintf (fp, "Volume%d.snapshot%d.id: %s\n", volcount, snapcount,
-                         gf_strdup (uuid_utoa (snapinfo->snap_id)));
+                         uuid_utoa (snapinfo->snap_id));
                 fprintf (fp, "Volume%d.snapshot%d.time: %s\n",
                          volcount, snapcount, timestr);
 
@@ -5494,6 +5498,7 @@ glusterd_get_state (rpcsvc_request_t *req, dict_t *dict)
                                 GD_MSG_DICT_GET_FAILED, "%s", err_str);
                 }
 
+                GF_FREE (odir);
                 ret = -1;
                 goto out;
         }
@@ -5528,7 +5533,7 @@ glusterd_get_state (rpcsvc_request_t *req, dict_t *dict)
         GF_FREE (odir);
         GF_FREE (filename);
 
-        ret = dict_set_str (dict, "ofilepath", ofilepath);
+        ret = dict_set_dynstr (dict, "ofilepath", ofilepath);
         if (ret) {
                 gf_msg (this->name, GF_LOG_ERROR, 0,
                         GD_MSG_DICT_SET_FAILED, "Unable to set output path");
@@ -5568,6 +5573,7 @@ glusterd_get_state (rpcsvc_request_t *req, dict_t *dict)
                                         GD_MSG_VOL_OPTS_IMPORT_FAIL, "Failed to "
                                         "fetch the value of all volume options "
                                         "for volume %s", volinfo->volname);
+                                dict_unref (vol_all_opts);
                                 continue;
                         }
 
@@ -5942,7 +5948,7 @@ out:
                                            &rsp.dict.dict_len);
         glusterd_to_cli (req, &rsp, NULL, 0, NULL,
                          (xdrproc_t)xdr_gf_cli_rsp, dict);
-
+        GF_FREE(rsp.dict.dict_val);
         return ret;
 }
 
@@ -5986,6 +5992,7 @@ __glusterd_handle_get_state (rpcsvc_request_t *req)
                                 "unserialize req-buffer to dictionary");
                         snprintf (err_str, sizeof (err_str), "Unable to decode"
                                   " the command");
+                        free (cli_req.dict.dict_val);
                         goto out;
                 } else {
                         dict->extra_stdfree = cli_req.dict.dict_val;
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
index 0fe56ebbc..e21ec4e5d 100644
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
@@ -13125,6 +13125,7 @@ glusterd_get_default_val_for_volopt (dict_t *ctx, gf_boolean_t all_opts,
         char                    *def_val = NULL;
         char                     dict_key[50] = {0,};
         gf_boolean_t             key_found = _gf_false;
+        gf_boolean_t             get_value_vme = _gf_false;
         glusterd_conf_t         *priv = NULL;
         dict_t                  *vol_dict = NULL;
 
@@ -13149,6 +13150,7 @@ glusterd_get_default_val_for_volopt (dict_t *ctx, gf_boolean_t all_opts,
                 if (!all_opts && strcmp (vme->key, input_key))
                         continue;
                 key_found = _gf_true;
+                get_value_vme = _gf_false;
                 /* First look for the key in the priv->opts for global option
                  * and then into vol_dict, if its not present then look for
                  * translator default value */
@@ -13164,6 +13166,7 @@ glusterd_get_default_val_for_volopt (dict_t *ctx, gf_boolean_t all_opts,
                                 } else {
                                         ret = glusterd_get_value_for_vme_entry
                                                  (vme, &def_val);
+                                        get_value_vme = _gf_true;
                                         if (!all_opts && ret)
                                                 goto out;
                                         else if (ret == -2)
@@ -13179,6 +13182,8 @@ glusterd_get_default_val_for_volopt (dict_t *ctx, gf_boolean_t all_opts,
                                 GD_MSG_DICT_SET_FAILED,
                                 "Failed to "
                                 "set %s in dictionary", vme->key);
+                        if (get_value_vme)
+                                GF_FREE (def_val);
                         goto out;
                 }
                 sprintf (dict_key, "value%d", count);
@@ -13189,8 +13194,14 @@ glusterd_get_default_val_for_volopt (dict_t *ctx, gf_boolean_t all_opts,
                                 "Failed to "
                                 "set %s for key %s in dictionary", def_val,
                                 vme->key);
+                        if (get_value_vme)
+                                GF_FREE (def_val);
+
                         goto out;
                 }
+                if (get_value_vme)
+                        GF_FREE (def_val);
+
                 def_val = NULL;
                 if (!all_opts)
                         break;
-- 
2.20.1