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