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