From ab56ec1e99cd76d45b52d841e6b0009f94a3268b Mon Sep 17 00:00:00 2001 From: Zhou Zhengping Date: Sun, 10 Jul 2016 09:10:49 -0400 Subject: rpc: fix several problems in failure handle logic Once dynstr is set into a dict by function dict_set_dynstr, its free operation will be called by this dict when the dict is destroyed. Signed-off-by: Zhou Zhengping Change-Id: Idd2bd19a041bcb477e1c897428ca1740fb75c5f3 BUG: 1354141 Reviewed-on: http://review.gluster.org/14882 Tested-by: Zhou Zhengping NetBSD-regression: NetBSD Build System CentOS-regression: Gluster Build System Reviewed-by: Vijay Bellur Smoke: Gluster Build System --- rpc/rpc-lib/src/rpc-transport.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'rpc/rpc-lib') diff --git a/rpc/rpc-lib/src/rpc-transport.c b/rpc/rpc-lib/src/rpc-transport.c index e224dcc022e..1216b9fb3df 100644 --- a/rpc/rpc-lib/src/rpc-transport.c +++ b/rpc/rpc-lib/src/rpc-transport.c @@ -617,8 +617,10 @@ rpc_transport_unix_options_build (dict_t **options, char *filepath, } ret = dict_set_dynstr (dict, "transport.socket.connect-path", fpath); - if (ret) + if (ret) { + GF_FREE (fpath); goto out; + } ret = dict_set_str (dict, "transport.address-family", "unix"); if (ret) @@ -644,10 +646,8 @@ rpc_transport_unix_options_build (dict_t **options, char *filepath, *options = dict; out: - if (ret) { - GF_FREE (fpath); - if (dict) - dict_unref (dict); + if (ret && dict) { + dict_unref (dict); } return ret; } @@ -676,6 +676,7 @@ rpc_transport_inet_options_build (dict_t **options, const char *hostname, ret = dict_set_dynstr (dict, "remote-host", host); if (ret) { + GF_FREE (host); gf_log (THIS->name, GF_LOG_WARNING, "failed to set remote-host with %s", host); goto out; @@ -697,10 +698,8 @@ rpc_transport_inet_options_build (dict_t **options, const char *hostname, *options = dict; out: - if (ret) { - GF_FREE (host); - if (dict) - dict_unref (dict); + if (ret && dict) { + dict_unref (dict); } return ret; -- cgit