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