14f8ab
From df6523ed3c5267624197b52edcb553fc2d8a08f2 Mon Sep 17 00:00:00 2001
14f8ab
From: Mohammed Rafi KC <rkavunga@redhat.com>
14f8ab
Date: Tue, 26 Feb 2019 18:04:18 +0530
14f8ab
Subject: [PATCH 102/124] rpc/transport: Missing a ref on dict while creating
14f8ab
 transport object
14f8ab
14f8ab
while creating rpc_tranpsort object, we store a dictionary without
14f8ab
taking a ref on dict but it does an unref during the cleaning of the
14f8ab
transport object.
14f8ab
14f8ab
So the rpc layer expect the caller to take a ref on the dictionary
14f8ab
before passing dict to rpc layer. This leads to a lot of confusion
14f8ab
across the code base and leads to ref leaks.
14f8ab
14f8ab
Semantically, this is not correct. It is the rpc layer responsibility
14f8ab
to take a ref when storing it, and free during the cleanup.
14f8ab
14f8ab
I'm listing down the total issues or leaks across the code base because
14f8ab
of this confusion. These issues are currently present in the upstream
14f8ab
master.
14f8ab
14f8ab
1) changelog_rpc_client_init
14f8ab
14f8ab
2) quota_enforcer_init
14f8ab
14f8ab
3) rpcsvc_create_listeners : when there are two transport, like tcp,rdma.
14f8ab
14f8ab
4) quotad_aggregator_init
14f8ab
14f8ab
5) glusterd: init
14f8ab
14f8ab
6) nfs3_init_state
14f8ab
14f8ab
7) server: init
14f8ab
14f8ab
8) client:init
14f8ab
14f8ab
This patch does the cleanup according to the semantics.
14f8ab
14f8ab
Backport of : https://review.gluster.org/#/c/glusterfs/+/22266/
14f8ab
14f8ab
>Change-Id: I46373af9630373eb375ee6de0e6f2bbe2a677425
14f8ab
>updates: bz#1659708
14f8ab
>Signed-off-by: Mohammed Rafi KC <rkavunga@redhat.com>
14f8ab
14f8ab
Change-Id: Iff978497e11592fbebfa4b683fdc56698b782859
14f8ab
BUG: 1471742
14f8ab
Signed-off-by: Mohammed Rafi KC <rkavunga@redhat.com>
14f8ab
Reviewed-on: https://code.engineering.redhat.com/gerrit/167847
14f8ab
Tested-by: RHGS Build Bot <nigelb@redhat.com>
14f8ab
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
14f8ab
---
14f8ab
 api/src/glfs-mgmt.c                                | 10 ++++--
14f8ab
 cli/src/cli.c                                      | 20 +++++++-----
14f8ab
 glusterfsd/src/glusterfsd-mgmt.c                   | 18 ++++++++--
14f8ab
 rpc/rpc-lib/src/rpc-clnt.c                         |  2 --
14f8ab
 rpc/rpc-lib/src/rpc-transport.c                    | 38 +++++++---------------
14f8ab
 rpc/rpc-lib/src/rpc-transport.h                    |  4 +--
14f8ab
 rpc/rpc-lib/src/rpcsvc.c                           | 13 ++------
14f8ab
 rpc/rpc-lib/src/rpcsvc.h                           |  2 +-
14f8ab
 .../features/changelog/src/changelog-rpc-common.c  |  9 +++--
14f8ab
 .../snapview-server/src/snapview-server-mgmt.c     |  8 ++++-
14f8ab
 xlators/mgmt/glusterd/src/glusterd-conn-mgmt.c     |  8 ++++-
14f8ab
 xlators/mgmt/glusterd/src/glusterd-handler.c       | 18 ++++++----
14f8ab
 xlators/mgmt/glusterd/src/glusterd-rebalance.c     |  8 ++++-
14f8ab
 xlators/mgmt/glusterd/src/glusterd-utils.c         |  9 +++--
14f8ab
 xlators/mgmt/glusterd/src/glusterd.c               |  6 +++-
14f8ab
 xlators/nfs/server/src/acl3.c                      |  5 +++
14f8ab
 xlators/nfs/server/src/mount3.c                    |  5 +++
14f8ab
 xlators/nfs/server/src/nlm4.c                      |  7 ++++
14f8ab
 18 files changed, 119 insertions(+), 71 deletions(-)
14f8ab
14f8ab
diff --git a/api/src/glfs-mgmt.c b/api/src/glfs-mgmt.c
14f8ab
index d502b4f..7476d5b 100644
14f8ab
--- a/api/src/glfs-mgmt.c
14f8ab
+++ b/api/src/glfs-mgmt.c
14f8ab
@@ -1015,6 +1015,10 @@ glfs_mgmt_init(struct glfs *fs)
14f8ab
     if (ctx->mgmt)
14f8ab
         return 0;
14f8ab
 
14f8ab
+    options = dict_new();
14f8ab
+    if (!options)
14f8ab
+        goto out;
14f8ab
+
14f8ab
     if (cmd_args->volfile_server_port)
14f8ab
         port = cmd_args->volfile_server_port;
14f8ab
 
14f8ab
@@ -1029,11 +1033,11 @@ glfs_mgmt_init(struct glfs *fs)
14f8ab
 
14f8ab
     if (cmd_args->volfile_server_transport &&
14f8ab
         !strcmp(cmd_args->volfile_server_transport, "unix")) {
14f8ab
-        ret = rpc_transport_unix_options_build(&options, host, 0);
14f8ab
+        ret = rpc_transport_unix_options_build(options, host, 0);
14f8ab
     } else {
14f8ab
         xlator_cmdline_option_t *opt = find_xlator_option_in_cmd_args_t(
14f8ab
             "address-family", cmd_args);
14f8ab
-        ret = rpc_transport_inet_options_build(&options, host, port,
14f8ab
+        ret = rpc_transport_inet_options_build(options, host, port,
14f8ab
                                                (opt ? opt->value : NULL));
14f8ab
     }
14f8ab
 
14f8ab
@@ -1075,5 +1079,7 @@ glfs_mgmt_init(struct glfs *fs)
14f8ab
 
14f8ab
     ret = rpc_clnt_start(rpc);
14f8ab
 out:
14f8ab
+    if (options)
14f8ab
+        dict_unref(options);
14f8ab
     return ret;
14f8ab
 }
14f8ab
diff --git a/cli/src/cli.c b/cli/src/cli.c
14f8ab
index c33d152..ff39a98 100644
14f8ab
--- a/cli/src/cli.c
14f8ab
+++ b/cli/src/cli.c
14f8ab
@@ -661,9 +661,8 @@ cli_quotad_clnt_rpc_init(void)
14f8ab
 
14f8ab
     global_quotad_rpc = rpc;
14f8ab
 out:
14f8ab
-    if (ret) {
14f8ab
-        if (rpc_opts)
14f8ab
-            dict_unref(rpc_opts);
14f8ab
+    if (rpc_opts) {
14f8ab
+        dict_unref(rpc_opts);
14f8ab
     }
14f8ab
     return rpc;
14f8ab
 }
14f8ab
@@ -685,6 +684,10 @@ cli_rpc_init(struct cli_state *state)
14f8ab
     this = THIS;
14f8ab
     cli_rpc_prog = &cli_prog;
14f8ab
 
14f8ab
+    options = dict_new();
14f8ab
+    if (!options)
14f8ab
+        goto out;
14f8ab
+
14f8ab
     /* If address family specified in CLI */
14f8ab
     if (state->address_family) {
14f8ab
         addr_family = state->address_family;
14f8ab
@@ -699,7 +702,7 @@ cli_rpc_init(struct cli_state *state)
14f8ab
                "Connecting to glusterd using "
14f8ab
                "sockfile %s",
14f8ab
                state->glusterd_sock);
14f8ab
-        ret = rpc_transport_unix_options_build(&options, state->glusterd_sock,
14f8ab
+        ret = rpc_transport_unix_options_build(options, state->glusterd_sock,
14f8ab
                                                0);
14f8ab
         if (ret)
14f8ab
             goto out;
14f8ab
@@ -709,10 +712,6 @@ cli_rpc_init(struct cli_state *state)
14f8ab
                "%s",
14f8ab
                state->remote_host);
14f8ab
 
14f8ab
-        options = dict_new();
14f8ab
-        if (!options)
14f8ab
-            goto out;
14f8ab
-
14f8ab
         ret = dict_set_str(options, "remote-host", state->remote_host);
14f8ab
         if (ret)
14f8ab
             goto out;
14f8ab
@@ -731,7 +730,7 @@ cli_rpc_init(struct cli_state *state)
14f8ab
         gf_log("cli", GF_LOG_DEBUG,
14f8ab
                "Connecting to glusterd using "
14f8ab
                "default socket");
14f8ab
-        ret = rpc_transport_unix_options_build(&options,
14f8ab
+        ret = rpc_transport_unix_options_build(options,
14f8ab
                                                DEFAULT_GLUSTERD_SOCKFILE, 0);
14f8ab
         if (ret)
14f8ab
             goto out;
14f8ab
@@ -749,6 +748,9 @@ cli_rpc_init(struct cli_state *state)
14f8ab
 
14f8ab
     ret = rpc_clnt_start(rpc);
14f8ab
 out:
14f8ab
+    if (options)
14f8ab
+        dict_unref(options);
14f8ab
+
14f8ab
     if (ret) {
14f8ab
         if (rpc)
14f8ab
             rpc_clnt_unref(rpc);
14f8ab
diff --git a/glusterfsd/src/glusterfsd-mgmt.c b/glusterfsd/src/glusterfsd-mgmt.c
14f8ab
index a89c980..1d2cd1a 100644
14f8ab
--- a/glusterfsd/src/glusterfsd-mgmt.c
14f8ab
+++ b/glusterfsd/src/glusterfsd-mgmt.c
14f8ab
@@ -2781,7 +2781,11 @@ glusterfs_listener_init(glusterfs_ctx_t *ctx)
14f8ab
     if (!cmd_args->sock_file)
14f8ab
         return 0;
14f8ab
 
14f8ab
-    ret = rpcsvc_transport_unix_options_build(&options, cmd_args->sock_file);
14f8ab
+    options = dict_new();
14f8ab
+    if (!options)
14f8ab
+        goto out;
14f8ab
+
14f8ab
+    ret = rpcsvc_transport_unix_options_build(options, cmd_args->sock_file);
14f8ab
     if (ret)
14f8ab
         goto out;
14f8ab
 
14f8ab
@@ -2808,6 +2812,8 @@ glusterfs_listener_init(glusterfs_ctx_t *ctx)
14f8ab
     ctx->listener = rpc;
14f8ab
 
14f8ab
 out:
14f8ab
+    if (options)
14f8ab
+        dict_unref(options);
14f8ab
     return ret;
14f8ab
 }
14f8ab
 
14f8ab
@@ -2889,6 +2895,10 @@ glusterfs_mgmt_init(glusterfs_ctx_t *ctx)
14f8ab
     if (ctx->mgmt)
14f8ab
         return 0;
14f8ab
 
14f8ab
+    options = dict_new();
14f8ab
+    if (!options)
14f8ab
+        goto out;
14f8ab
+
14f8ab
     LOCK_INIT(&ctx->volfile_lock);
14f8ab
 
14f8ab
     if (cmd_args->volfile_server_port)
14f8ab
@@ -2898,10 +2908,10 @@ glusterfs_mgmt_init(glusterfs_ctx_t *ctx)
14f8ab
 
14f8ab
     if (cmd_args->volfile_server_transport &&
14f8ab
         !strcmp(cmd_args->volfile_server_transport, "unix")) {
14f8ab
-        ret = rpc_transport_unix_options_build(&options, host, 0);
14f8ab
+        ret = rpc_transport_unix_options_build(options, host, 0);
14f8ab
     } else {
14f8ab
         opt = find_xlator_option_in_cmd_args_t("address-family", cmd_args);
14f8ab
-        ret = rpc_transport_inet_options_build(&options, host, port,
14f8ab
+        ret = rpc_transport_inet_options_build(options, host, port,
14f8ab
                                                (opt ? opt->value : NULL));
14f8ab
     }
14f8ab
     if (ret)
14f8ab
@@ -2950,6 +2960,8 @@ glusterfs_mgmt_init(glusterfs_ctx_t *ctx)
14f8ab
 
14f8ab
     ret = rpc_clnt_start(rpc);
14f8ab
 out:
14f8ab
+    if (options)
14f8ab
+        dict_unref(options);
14f8ab
     return ret;
14f8ab
 }
14f8ab
 
14f8ab
diff --git a/rpc/rpc-lib/src/rpc-clnt.c b/rpc/rpc-lib/src/rpc-clnt.c
14f8ab
index 6f47515..b04eaed 100644
14f8ab
--- a/rpc/rpc-lib/src/rpc-clnt.c
14f8ab
+++ b/rpc/rpc-lib/src/rpc-clnt.c
14f8ab
@@ -1125,8 +1125,6 @@ rpc_clnt_new(dict_t *options, xlator_t *owner, char *name,
14f8ab
         mem_pool_destroy(rpc->saved_frames_pool);
14f8ab
         GF_FREE(rpc);
14f8ab
         rpc = NULL;
14f8ab
-        if (options)
14f8ab
-            dict_unref(options);
14f8ab
         goto out;
14f8ab
     }
14f8ab
 
14f8ab
diff --git a/rpc/rpc-lib/src/rpc-transport.c b/rpc/rpc-lib/src/rpc-transport.c
14f8ab
index 4beaaf9..bed1f8c 100644
14f8ab
--- a/rpc/rpc-lib/src/rpc-transport.c
14f8ab
+++ b/rpc/rpc-lib/src/rpc-transport.c
14f8ab
@@ -168,6 +168,11 @@ rpc_transport_cleanup(rpc_transport_t *trans)
14f8ab
     if (trans->fini)
14f8ab
         trans->fini(trans);
14f8ab
 
14f8ab
+    if (trans->options) {
14f8ab
+        dict_unref(trans->options);
14f8ab
+        trans->options = NULL;
14f8ab
+    }
14f8ab
+
14f8ab
     GF_FREE(trans->name);
14f8ab
 
14f8ab
     if (trans->xl)
14f8ab
@@ -352,7 +357,7 @@ rpc_transport_load(glusterfs_ctx_t *ctx, dict_t *options, char *trans_name)
14f8ab
         }
14f8ab
     }
14f8ab
 
14f8ab
-    trans->options = options;
14f8ab
+    trans->options = dict_ref(options);
14f8ab
 
14f8ab
     pthread_mutex_init(&trans->lock, NULL);
14f8ab
     trans->xl = this;
14f8ab
@@ -591,19 +596,14 @@ out:
14f8ab
 }
14f8ab
 
14f8ab
 int
14f8ab
-rpc_transport_unix_options_build(dict_t **options, char *filepath,
14f8ab
+rpc_transport_unix_options_build(dict_t *dict, char *filepath,
14f8ab
                                  int frame_timeout)
14f8ab
 {
14f8ab
-    dict_t *dict = NULL;
14f8ab
     char *fpath = NULL;
14f8ab
     int ret = -1;
14f8ab
 
14f8ab
     GF_ASSERT(filepath);
14f8ab
-    GF_ASSERT(options);
14f8ab
-
14f8ab
-    dict = dict_new();
14f8ab
-    if (!dict)
14f8ab
-        goto out;
14f8ab
+    GF_VALIDATE_OR_GOTO("rpc-transport", dict, out);
14f8ab
 
14f8ab
     fpath = gf_strdup(filepath);
14f8ab
     if (!fpath) {
14f8ab
@@ -638,20 +638,14 @@ rpc_transport_unix_options_build(dict_t **options, char *filepath,
14f8ab
         if (ret)
14f8ab
             goto out;
14f8ab
     }
14f8ab
-
14f8ab
-    *options = dict;
14f8ab
 out:
14f8ab
-    if (ret && dict) {
14f8ab
-        dict_unref(dict);
14f8ab
-    }
14f8ab
     return ret;
14f8ab
 }
14f8ab
 
14f8ab
 int
14f8ab
-rpc_transport_inet_options_build(dict_t **options, const char *hostname,
14f8ab
-                                 int port, char *af)
14f8ab
+rpc_transport_inet_options_build(dict_t *dict, const char *hostname, int port,
14f8ab
+                                 char *af)
14f8ab
 {
14f8ab
-    dict_t *dict = NULL;
14f8ab
     char *host = NULL;
14f8ab
     int ret = -1;
14f8ab
 #ifdef IPV6_DEFAULT
14f8ab
@@ -660,13 +654,9 @@ rpc_transport_inet_options_build(dict_t **options, const char *hostname,
14f8ab
     char *addr_family = "inet";
14f8ab
 #endif
14f8ab
 
14f8ab
-    GF_ASSERT(options);
14f8ab
     GF_ASSERT(hostname);
14f8ab
     GF_ASSERT(port >= 1024);
14f8ab
-
14f8ab
-    dict = dict_new();
14f8ab
-    if (!dict)
14f8ab
-        goto out;
14f8ab
+    GF_VALIDATE_OR_GOTO("rpc-transport", dict, out);
14f8ab
 
14f8ab
     host = gf_strdup((char *)hostname);
14f8ab
     if (!host) {
14f8ab
@@ -702,12 +692,6 @@ rpc_transport_inet_options_build(dict_t **options, const char *hostname,
14f8ab
                "failed to set trans-type with socket");
14f8ab
         goto out;
14f8ab
     }
14f8ab
-
14f8ab
-    *options = dict;
14f8ab
 out:
14f8ab
-    if (ret && dict) {
14f8ab
-        dict_unref(dict);
14f8ab
-    }
14f8ab
-
14f8ab
     return ret;
14f8ab
 }
14f8ab
diff --git a/rpc/rpc-lib/src/rpc-transport.h b/rpc/rpc-lib/src/rpc-transport.h
14f8ab
index 9e75d1a..64b7e9b 100644
14f8ab
--- a/rpc/rpc-lib/src/rpc-transport.h
14f8ab
+++ b/rpc/rpc-lib/src/rpc-transport.h
14f8ab
@@ -303,11 +303,11 @@ rpc_transport_keepalive_options_set(dict_t *options, int32_t interval,
14f8ab
                                     int32_t time, int32_t timeout);
14f8ab
 
14f8ab
 int
14f8ab
-rpc_transport_unix_options_build(dict_t **options, char *filepath,
14f8ab
+rpc_transport_unix_options_build(dict_t *options, char *filepath,
14f8ab
                                  int frame_timeout);
14f8ab
 
14f8ab
 int
14f8ab
-rpc_transport_inet_options_build(dict_t **options, const char *hostname,
14f8ab
+rpc_transport_inet_options_build(dict_t *options, const char *hostname,
14f8ab
                                  int port, char *af);
14f8ab
 
14f8ab
 void
14f8ab
diff --git a/rpc/rpc-lib/src/rpcsvc.c b/rpc/rpc-lib/src/rpcsvc.c
14f8ab
index 74373c4..5a35139 100644
14f8ab
--- a/rpc/rpc-lib/src/rpcsvc.c
14f8ab
+++ b/rpc/rpc-lib/src/rpcsvc.c
14f8ab
@@ -2615,18 +2615,13 @@ rpcsvc_reconfigure_options(rpcsvc_t *svc, dict_t *options)
14f8ab
 }
14f8ab
 
14f8ab
 int
14f8ab
-rpcsvc_transport_unix_options_build(dict_t **options, char *filepath)
14f8ab
+rpcsvc_transport_unix_options_build(dict_t *dict, char *filepath)
14f8ab
 {
14f8ab
-    dict_t *dict = NULL;
14f8ab
     char *fpath = NULL;
14f8ab
     int ret = -1;
14f8ab
 
14f8ab
     GF_ASSERT(filepath);
14f8ab
-    GF_ASSERT(options);
14f8ab
-
14f8ab
-    dict = dict_new();
14f8ab
-    if (!dict)
14f8ab
-        goto out;
14f8ab
+    GF_VALIDATE_OR_GOTO("rpcsvc", dict, out);
14f8ab
 
14f8ab
     fpath = gf_strdup(filepath);
14f8ab
     if (!fpath) {
14f8ab
@@ -2649,13 +2644,9 @@ rpcsvc_transport_unix_options_build(dict_t **options, char *filepath)
14f8ab
     ret = dict_set_str(dict, "transport-type", "socket");
14f8ab
     if (ret)
14f8ab
         goto out;
14f8ab
-
14f8ab
-    *options = dict;
14f8ab
 out:
14f8ab
     if (ret) {
14f8ab
         GF_FREE(fpath);
14f8ab
-        if (dict)
14f8ab
-            dict_unref(dict);
14f8ab
     }
14f8ab
     return ret;
14f8ab
 }
14f8ab
diff --git a/rpc/rpc-lib/src/rpcsvc.h b/rpc/rpc-lib/src/rpcsvc.h
14f8ab
index 34045ce..a51edc7 100644
14f8ab
--- a/rpc/rpc-lib/src/rpcsvc.h
14f8ab
+++ b/rpc/rpc-lib/src/rpcsvc.h
14f8ab
@@ -665,7 +665,7 @@ rpcsvc_actor_t *
14f8ab
 rpcsvc_program_actor(rpcsvc_request_t *req);
14f8ab
 
14f8ab
 int
14f8ab
-rpcsvc_transport_unix_options_build(dict_t **options, char *filepath);
14f8ab
+rpcsvc_transport_unix_options_build(dict_t *options, char *filepath);
14f8ab
 int
14f8ab
 rpcsvc_set_allow_insecure(rpcsvc_t *svc, dict_t *options);
14f8ab
 int
14f8ab
diff --git a/xlators/features/changelog/src/changelog-rpc-common.c b/xlators/features/changelog/src/changelog-rpc-common.c
14f8ab
index cf35175..dcdcfb1 100644
14f8ab
--- a/xlators/features/changelog/src/changelog-rpc-common.c
14f8ab
+++ b/xlators/features/changelog/src/changelog-rpc-common.c
14f8ab
@@ -47,7 +47,7 @@ changelog_rpc_client_init(xlator_t *this, void *cbkdata, char *sockfile,
14f8ab
     if (!options)
14f8ab
         goto error_return;
14f8ab
 
14f8ab
-    ret = rpc_transport_unix_options_build(&options, sockfile, 0);
14f8ab
+    ret = rpc_transport_unix_options_build(options, sockfile, 0);
14f8ab
     if (ret) {
14f8ab
         gf_msg(this->name, GF_LOG_ERROR, 0, CHANGELOG_MSG_RPC_BUILD_ERROR,
14f8ab
                "failed to build rpc options");
14f8ab
@@ -73,6 +73,7 @@ changelog_rpc_client_init(xlator_t *this, void *cbkdata, char *sockfile,
14f8ab
         goto dealloc_rpc_clnt;
14f8ab
     }
14f8ab
 
14f8ab
+    dict_unref(options);
14f8ab
     return rpc;
14f8ab
 
14f8ab
 dealloc_rpc_clnt:
14f8ab
@@ -303,7 +304,11 @@ changelog_rpc_server_init(xlator_t *this, char *sockfile, void *cbkdata,
14f8ab
     if (!cbkdata)
14f8ab
         cbkdata = this;
14f8ab
 
14f8ab
-    ret = rpcsvc_transport_unix_options_build(&options, sockfile);
14f8ab
+    options = dict_new();
14f8ab
+    if (!options)
14f8ab
+        return NULL;
14f8ab
+
14f8ab
+    ret = rpcsvc_transport_unix_options_build(options, sockfile);
14f8ab
     if (ret)
14f8ab
         goto dealloc_dict;
14f8ab
 
14f8ab
diff --git a/xlators/features/snapview-server/src/snapview-server-mgmt.c b/xlators/features/snapview-server/src/snapview-server-mgmt.c
14f8ab
index b608cdf..bc415ef 100644
14f8ab
--- a/xlators/features/snapview-server/src/snapview-server-mgmt.c
14f8ab
+++ b/xlators/features/snapview-server/src/snapview-server-mgmt.c
14f8ab
@@ -101,8 +101,12 @@ svs_mgmt_init(xlator_t *this)
14f8ab
     if (cmd_args->volfile_server)
14f8ab
         host = cmd_args->volfile_server;
14f8ab
 
14f8ab
+    options = dict_new();
14f8ab
+    if (!options)
14f8ab
+        goto out;
14f8ab
+
14f8ab
     opt = find_xlator_option_in_cmd_args_t("address-family", cmd_args);
14f8ab
-    ret = rpc_transport_inet_options_build(&options, host, port,
14f8ab
+    ret = rpc_transport_inet_options_build(options, host, port,
14f8ab
                                            (opt != NULL ? opt->value : NULL));
14f8ab
     if (ret) {
14f8ab
         gf_msg(this->name, GF_LOG_ERROR, 0, SVS_MSG_BUILD_TRNSPRT_OPT_FAILED,
14f8ab
@@ -145,6 +149,8 @@ svs_mgmt_init(xlator_t *this)
14f8ab
     gf_msg_debug(this->name, 0, "svs mgmt init successful");
14f8ab
 
14f8ab
 out:
14f8ab
+    if (options)
14f8ab
+        dict_unref(options);
14f8ab
     if (ret)
14f8ab
         if (priv) {
14f8ab
             rpc_clnt_connection_cleanup(&priv->rpc->conn);
14f8ab
diff --git a/xlators/mgmt/glusterd/src/glusterd-conn-mgmt.c b/xlators/mgmt/glusterd/src/glusterd-conn-mgmt.c
14f8ab
index 052438c..16eefa1 100644
14f8ab
--- a/xlators/mgmt/glusterd/src/glusterd-conn-mgmt.c
14f8ab
+++ b/xlators/mgmt/glusterd/src/glusterd-conn-mgmt.c
14f8ab
@@ -29,6 +29,10 @@ glusterd_conn_init(glusterd_conn_t *conn, char *sockpath, int frame_timeout,
14f8ab
     if (!this)
14f8ab
         goto out;
14f8ab
 
14f8ab
+    options = dict_new();
14f8ab
+    if (!options)
14f8ab
+        goto out;
14f8ab
+
14f8ab
     svc = glusterd_conn_get_svc_object(conn);
14f8ab
     if (!svc) {
14f8ab
         gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_SVC_GET_FAIL,
14f8ab
@@ -36,7 +40,7 @@ glusterd_conn_init(glusterd_conn_t *conn, char *sockpath, int frame_timeout,
14f8ab
         goto out;
14f8ab
     }
14f8ab
 
14f8ab
-    ret = rpc_transport_unix_options_build(&options, sockpath, frame_timeout);
14f8ab
+    ret = rpc_transport_unix_options_build(options, sockpath, frame_timeout);
14f8ab
     if (ret)
14f8ab
         goto out;
14f8ab
 
14f8ab
@@ -66,6 +70,8 @@ glusterd_conn_init(glusterd_conn_t *conn, char *sockpath, int frame_timeout,
14f8ab
     conn->rpc = rpc;
14f8ab
     conn->notify = notify;
14f8ab
 out:
14f8ab
+    if (options)
14f8ab
+        dict_unref(options);
14f8ab
     if (ret) {
14f8ab
         if (rpc) {
14f8ab
             rpc_clnt_unref(rpc);
14f8ab
diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c
14f8ab
index 1cb9013..6147995 100644
14f8ab
--- a/xlators/mgmt/glusterd/src/glusterd-handler.c
14f8ab
+++ b/xlators/mgmt/glusterd/src/glusterd-handler.c
14f8ab
@@ -3493,11 +3493,10 @@ out:
14f8ab
 }
14f8ab
 
14f8ab
 int
14f8ab
-glusterd_transport_inet_options_build(dict_t **options, const char *hostname,
14f8ab
+glusterd_transport_inet_options_build(dict_t *dict, const char *hostname,
14f8ab
                                       int port, char *af)
14f8ab
 {
14f8ab
     xlator_t *this = NULL;
14f8ab
-    dict_t *dict = NULL;
14f8ab
     int32_t interval = -1;
14f8ab
     int32_t time = -1;
14f8ab
     int32_t timeout = -1;
14f8ab
@@ -3505,14 +3504,14 @@ glusterd_transport_inet_options_build(dict_t **options, const char *hostname,
14f8ab
 
14f8ab
     this = THIS;
14f8ab
     GF_ASSERT(this);
14f8ab
-    GF_ASSERT(options);
14f8ab
+    GF_ASSERT(dict);
14f8ab
     GF_ASSERT(hostname);
14f8ab
 
14f8ab
     if (!port)
14f8ab
         port = GLUSTERD_DEFAULT_PORT;
14f8ab
 
14f8ab
     /* Build default transport options */
14f8ab
-    ret = rpc_transport_inet_options_build(&dict, hostname, port, af);
14f8ab
+    ret = rpc_transport_inet_options_build(dict, hostname, port, af);
14f8ab
     if (ret)
14f8ab
         goto out;
14f8ab
 
14f8ab
@@ -3552,7 +3551,6 @@ glusterd_transport_inet_options_build(dict_t **options, const char *hostname,
14f8ab
     if ((interval > 0) || (time > 0))
14f8ab
         ret = rpc_transport_keepalive_options_set(dict, interval, time,
14f8ab
                                                   timeout);
14f8ab
-    *options = dict;
14f8ab
 out:
14f8ab
     gf_msg_debug("glusterd", 0, "Returning %d", ret);
14f8ab
     return ret;
14f8ab
@@ -3572,6 +3570,10 @@ glusterd_friend_rpc_create(xlator_t *this, glusterd_peerinfo_t *peerinfo,
14f8ab
     if (!peerctx)
14f8ab
         goto out;
14f8ab
 
14f8ab
+    options = dict_new();
14f8ab
+    if (!options)
14f8ab
+        goto out;
14f8ab
+
14f8ab
     if (args)
14f8ab
         peerctx->args = *args;
14f8ab
 
14f8ab
@@ -3586,7 +3588,7 @@ glusterd_friend_rpc_create(xlator_t *this, glusterd_peerinfo_t *peerinfo,
14f8ab
     if (ret)
14f8ab
         gf_log(this->name, GF_LOG_TRACE,
14f8ab
                "option transport.address-family is not set in xlator options");
14f8ab
-    ret = glusterd_transport_inet_options_build(&options, peerinfo->hostname,
14f8ab
+    ret = glusterd_transport_inet_options_build(options, peerinfo->hostname,
14f8ab
                                                 peerinfo->port, af);
14f8ab
     if (ret)
14f8ab
         goto out;
14f8ab
@@ -3596,6 +3598,7 @@ glusterd_friend_rpc_create(xlator_t *this, glusterd_peerinfo_t *peerinfo,
14f8ab
      * create our RPC endpoint with the same address that the peer would
14f8ab
      * use to reach us.
14f8ab
      */
14f8ab
+
14f8ab
     if (this->options) {
14f8ab
         data = dict_getn(this->options, "transport.socket.bind-address",
14f8ab
                          SLEN("transport.socket.bind-address"));
14f8ab
@@ -3637,6 +3640,9 @@ glusterd_friend_rpc_create(xlator_t *this, glusterd_peerinfo_t *peerinfo,
14f8ab
     peerctx = NULL;
14f8ab
     ret = 0;
14f8ab
 out:
14f8ab
+    if (options)
14f8ab
+        dict_unref(options);
14f8ab
+
14f8ab
     GF_FREE(peerctx);
14f8ab
     return ret;
14f8ab
 }
14f8ab
diff --git a/xlators/mgmt/glusterd/src/glusterd-rebalance.c b/xlators/mgmt/glusterd/src/glusterd-rebalance.c
14f8ab
index ed5ded5..cbed9a9 100644
14f8ab
--- a/xlators/mgmt/glusterd/src/glusterd-rebalance.c
14f8ab
+++ b/xlators/mgmt/glusterd/src/glusterd-rebalance.c
14f8ab
@@ -391,6 +391,10 @@ glusterd_rebalance_rpc_create(glusterd_volinfo_t *volinfo)
14f8ab
     if (!defrag)
14f8ab
         goto out;
14f8ab
 
14f8ab
+    options = dict_new();
14f8ab
+    if (!options)
14f8ab
+        goto out;
14f8ab
+
14f8ab
     GLUSTERD_GET_DEFRAG_SOCK_FILE(sockfile, volinfo);
14f8ab
     /* Check if defrag sockfile exists in the new location
14f8ab
      * in /var/run/ , if it does not try the old location
14f8ab
@@ -420,7 +424,7 @@ glusterd_rebalance_rpc_create(glusterd_volinfo_t *volinfo)
14f8ab
      * default timeout of 30mins used for unreliable network connections is
14f8ab
      * too long for unix domain socket connections.
14f8ab
      */
14f8ab
-    ret = rpc_transport_unix_options_build(&options, sockfile, 600);
14f8ab
+    ret = rpc_transport_unix_options_build(options, sockfile, 600);
14f8ab
     if (ret) {
14f8ab
         gf_msg(THIS->name, GF_LOG_ERROR, 0, GD_MSG_UNIX_OP_BUILD_FAIL,
14f8ab
                "Unix options build failed");
14f8ab
@@ -437,6 +441,8 @@ glusterd_rebalance_rpc_create(glusterd_volinfo_t *volinfo)
14f8ab
     }
14f8ab
     ret = 0;
14f8ab
 out:
14f8ab
+    if (options)
14f8ab
+        dict_unref(options);
14f8ab
     return ret;
14f8ab
 }
14f8ab
 
14f8ab
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
14f8ab
index ef664c2..2dd5f91 100644
14f8ab
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
14f8ab
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
14f8ab
@@ -1980,7 +1980,11 @@ glusterd_brick_connect(glusterd_volinfo_t *volinfo,
14f8ab
          * The default timeout of 30mins used for unreliable network
14f8ab
          * connections is too long for unix domain socket connections.
14f8ab
          */
14f8ab
-        ret = rpc_transport_unix_options_build(&options, socketpath, 600);
14f8ab
+        options = dict_new();
14f8ab
+        if (!options)
14f8ab
+            goto out;
14f8ab
+
14f8ab
+        ret = rpc_transport_unix_options_build(options, socketpath, 600);
14f8ab
         if (ret)
14f8ab
             goto out;
14f8ab
 
14f8ab
@@ -1999,7 +2003,8 @@ glusterd_brick_connect(glusterd_volinfo_t *volinfo,
14f8ab
         brickinfo->rpc = rpc;
14f8ab
     }
14f8ab
 out:
14f8ab
-
14f8ab
+    if (options)
14f8ab
+        dict_unref(options);
14f8ab
     gf_msg_debug("glusterd", 0, "Returning %d", ret);
14f8ab
     return ret;
14f8ab
 }
14f8ab
diff --git a/xlators/mgmt/glusterd/src/glusterd.c b/xlators/mgmt/glusterd/src/glusterd.c
14f8ab
index 89afb9c..d4ab630 100644
14f8ab
--- a/xlators/mgmt/glusterd/src/glusterd.c
14f8ab
+++ b/xlators/mgmt/glusterd/src/glusterd.c
14f8ab
@@ -1111,11 +1111,15 @@ glusterd_init_uds_listener(xlator_t *this)
14f8ab
 
14f8ab
     GF_ASSERT(this);
14f8ab
 
14f8ab
+    options = dict_new();
14f8ab
+    if (!options)
14f8ab
+        goto out;
14f8ab
+
14f8ab
     sock_data = dict_get(this->options, "glusterd-sockfile");
14f8ab
     (void)snprintf(sockfile, sizeof(sockfile), "%s",
14f8ab
                    sock_data ? sock_data->data : DEFAULT_GLUSTERD_SOCKFILE);
14f8ab
 
14f8ab
-    ret = rpcsvc_transport_unix_options_build(&options, sockfile);
14f8ab
+    ret = rpcsvc_transport_unix_options_build(options, sockfile);
14f8ab
     if (ret)
14f8ab
         goto out;
14f8ab
 
14f8ab
diff --git a/xlators/nfs/server/src/acl3.c b/xlators/nfs/server/src/acl3.c
14f8ab
index 0eca45d..2ede24b 100644
14f8ab
--- a/xlators/nfs/server/src/acl3.c
14f8ab
+++ b/xlators/nfs/server/src/acl3.c
14f8ab
@@ -787,9 +787,14 @@ acl3svc_init(xlator_t *nfsx)
14f8ab
         goto err;
14f8ab
     }
14f8ab
 
14f8ab
+    if (options)
14f8ab
+        dict_unref(options);
14f8ab
+
14f8ab
     acl3_inited = _gf_true;
14f8ab
     return &acl3prog;
14f8ab
 err:
14f8ab
+    if (options)
14f8ab
+        dict_unref(options);
14f8ab
     return NULL;
14f8ab
 }
14f8ab
 
14f8ab
diff --git a/xlators/nfs/server/src/mount3.c b/xlators/nfs/server/src/mount3.c
14f8ab
index 726dc29..396809c 100644
14f8ab
--- a/xlators/nfs/server/src/mount3.c
14f8ab
+++ b/xlators/nfs/server/src/mount3.c
14f8ab
@@ -4102,8 +4102,13 @@ mnt3svc_init(xlator_t *nfsx)
14f8ab
             gf_msg_debug(GF_MNT, GF_LOG_DEBUG, "Thread creation failed");
14f8ab
         }
14f8ab
     }
14f8ab
+    if (options)
14f8ab
+        dict_unref(options);
14f8ab
+
14f8ab
     return &mnt3prog;
14f8ab
 err:
14f8ab
+    if (options)
14f8ab
+        dict_unref(options);
14f8ab
     return NULL;
14f8ab
 }
14f8ab
 
14f8ab
diff --git a/xlators/nfs/server/src/nlm4.c b/xlators/nfs/server/src/nlm4.c
14f8ab
index a341ebd..c3c1453 100644
14f8ab
--- a/xlators/nfs/server/src/nlm4.c
14f8ab
+++ b/xlators/nfs/server/src/nlm4.c
14f8ab
@@ -1121,6 +1121,8 @@ nlm4_establish_callback(nfs3_call_state_t *cs, call_frame_t *cbk_frame)
14f8ab
         ret = 0;
14f8ab
 
14f8ab
 err:
14f8ab
+    if (options)
14f8ab
+        dict_unref(options);
14f8ab
     if (ret == -1) {
14f8ab
         if (rpc_clnt)
14f8ab
             rpc_clnt_unref(rpc_clnt);
14f8ab
@@ -2708,8 +2710,13 @@ nlm4svc_init(xlator_t *nfsx)
14f8ab
 
14f8ab
     gf_timer_call_after(nfsx->ctx, timeout, nlm_grace_period_over, NULL);
14f8ab
     nlm4_inited = _gf_true;
14f8ab
+
14f8ab
+    if (options)
14f8ab
+        dict_unref(options);
14f8ab
     return &nlm4prog;
14f8ab
 err:
14f8ab
+    if (options)
14f8ab
+        dict_unref(options);
14f8ab
     return NULL;
14f8ab
 }
14f8ab
 
14f8ab
-- 
14f8ab
1.8.3.1
14f8ab