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