From af7428490253421484e61409ddb77b653c4a5e63 Mon Sep 17 00:00:00 2001 From: Gaurav Kumar Garg Date: Wed, 9 Dec 2015 20:12:17 +0530 Subject: glusterd: fixing few memory leak in glusterd This patch is backport of: http://review.gluster.org/#/c/12927/ Current glusterd code base having memory leak. This is because of memory allocate by dict_allocate_and_serialize function in "gd_syncop_mgmt_v3_lock" and "gd_syncop_mgmt_v3_unlock" function is not freeing up memory upon exit. Fix is to free the memory after exit of the above function. Thanks Carlos and Roman for finding out the issue and fix. >> Change-Id: Id67aa794c84969830ca7ea8c2374f80c64d7a639 >> BUG: 1287517 >> Signed-off-by: Gaurav Kumar Garg >> Signed-off-by: Carlos Chinea >> Signed-off-by: Roman Tereshonkov >> Reviewed-on: http://review.gluster.org/12927 >> Smoke: Gluster Build System >> NetBSD-regression: NetBSD Build System >> CentOS-regression: Gluster Build System >> Reviewed-by: Jeff Darcy Change-Id: Id67aa794c84969830ca7ea8c2374f80c64d7a639 BUG: 1311377 Signed-off-by: Gaurav Kumar Garg (cherry picked from commit e38bf1bdeda3c7a89be3193ad62a72b9139358dd) Reviewed-on: http://review.gluster.org/13503 Smoke: Gluster Build System Reviewed-by: Vijay Bellur Tested-by: Vijay Bellur CentOS-regression: Gluster Build System NetBSD-regression: NetBSD Build System --- xlators/mgmt/glusterd/src/glusterd-handshake.c | 3 +++ xlators/mgmt/glusterd/src/glusterd-rpc-ops.c | 11 +++++++++++ xlators/mgmt/glusterd/src/glusterd-sm.c | 9 +++++++++ xlators/mgmt/glusterd/src/glusterd-store.c | 2 -- xlators/mgmt/glusterd/src/glusterd-syncop.c | 4 ++++ 5 files changed, 27 insertions(+), 2 deletions(-) (limited to 'xlators/mgmt/glusterd') diff --git a/xlators/mgmt/glusterd/src/glusterd-handshake.c b/xlators/mgmt/glusterd/src/glusterd-handshake.c index d2037fcd579..804e06ed01a 100644 --- a/xlators/mgmt/glusterd/src/glusterd-handshake.c +++ b/xlators/mgmt/glusterd/src/glusterd-handshake.c @@ -2205,5 +2205,8 @@ glusterd_peer_dump_version (xlator_t *this, struct rpc_clnt *rpc, unlock: rcu_read_unlock (); out: + if (ret && frame) + STACK_DESTROY (frame->root); + return ret; } diff --git a/xlators/mgmt/glusterd/src/glusterd-rpc-ops.c b/xlators/mgmt/glusterd/src/glusterd-rpc-ops.c index b6355e89026..acc4e559723 100644 --- a/xlators/mgmt/glusterd/src/glusterd-rpc-ops.c +++ b/xlators/mgmt/glusterd/src/glusterd-rpc-ops.c @@ -537,6 +537,7 @@ out: glusterd_friend_sm (); glusterd_op_sm (); } + if (ctx) glusterd_destroy_probe_ctx (ctx); free (rsp.hostname);//malloced by xdr @@ -1672,6 +1673,9 @@ glusterd_rpc_friend_update (call_frame_t *frame, xlator_t *this, out: GF_FREE (req.friends.friends_val); + if (ret && dummy_frame) + STACK_DESTROY (dummy_frame->root); + gf_msg_debug ("glusterd", 0, "Returning %d", ret); return ret; } @@ -1707,6 +1711,9 @@ glusterd_cluster_lock (call_frame_t *frame, xlator_t *this, (xdrproc_t)xdr_gd1_mgmt_cluster_lock_req); out: gf_msg_debug ("glusterd", 0, "Returning %d", ret); + + if (ret && dummy_frame) + STACK_DESTROY (dummy_frame->root); return ret; } @@ -1893,6 +1900,10 @@ glusterd_cluster_unlock (call_frame_t *frame, xlator_t *this, (xdrproc_t)xdr_gd1_mgmt_cluster_unlock_req); out: gf_msg_debug (this ? this->name : "glusterd", 0, "Returning %d", ret); + + if (ret && dummy_frame) + STACK_DESTROY (dummy_frame->root); + return ret; } diff --git a/xlators/mgmt/glusterd/src/glusterd-sm.c b/xlators/mgmt/glusterd/src/glusterd-sm.c index 4f345bc2c79..cbc5eeb2dbf 100644 --- a/xlators/mgmt/glusterd/src/glusterd-sm.c +++ b/xlators/mgmt/glusterd/src/glusterd-sm.c @@ -331,6 +331,9 @@ glusterd_ac_friend_add (glusterd_friend_sm_event_t *event, void *ctx) out: rcu_read_unlock (); + if (ret && frame) + STACK_DESTROY (frame->root); + gf_msg_debug ("glusterd", 0, "Returning with %d", ret); return ret; } @@ -412,6 +415,9 @@ out: dict_unref (dict); gf_msg_debug ("glusterd", 0, "Returning with %d", ret); + if (ret && frame) + STACK_DESTROY (frame->root); + return ret; } @@ -490,6 +496,9 @@ out: gf_msg_debug ("glusterd", 0, "Returning with %d", ret); + if (ret && frame) + STACK_DESTROY (frame->root); + return ret; } diff --git a/xlators/mgmt/glusterd/src/glusterd-store.c b/xlators/mgmt/glusterd/src/glusterd-store.c index b2247423619..361ecb88554 100644 --- a/xlators/mgmt/glusterd/src/glusterd-store.c +++ b/xlators/mgmt/glusterd/src/glusterd-store.c @@ -4024,7 +4024,6 @@ glusterd_store_retrieve_peers (xlator_t *this) struct dirent *entry = NULL; char path[PATH_MAX] = {0,}; glusterd_peerinfo_t *peerinfo = NULL; - char *hostname = NULL; gf_store_handle_t *shandle = NULL; char filepath[PATH_MAX] = {0,}; gf_store_iter_t *iter = NULL; @@ -4107,7 +4106,6 @@ glusterd_store_retrieve_peers (xlator_t *this) &op_errno); } if (op_errno != GD_STORE_EOF) { - GF_FREE(hostname); goto out; } diff --git a/xlators/mgmt/glusterd/src/glusterd-syncop.c b/xlators/mgmt/glusterd/src/glusterd-syncop.c index a0b856160c9..8ff7bdea818 100644 --- a/xlators/mgmt/glusterd/src/glusterd-syncop.c +++ b/xlators/mgmt/glusterd/src/glusterd-syncop.c @@ -215,6 +215,8 @@ out: iobref_unref (iobref); iobuf_unref (iobuf); + if (ret && frame) + STACK_DESTROY (frame->root); return ret; } @@ -411,6 +413,7 @@ gd_syncop_mgmt_v3_lock (glusterd_op_t op, dict_t *op_ctx, (xdrproc_t) xdr_gd1_mgmt_v3_lock_req); out: + GF_FREE (req.dict.dict_val); gf_msg_debug ("glusterd", 0, "Returning %d", ret); return ret; } @@ -510,6 +513,7 @@ gd_syncop_mgmt_v3_unlock (dict_t *op_ctx, glusterd_peerinfo_t *peerinfo, (xdrproc_t) xdr_gd1_mgmt_v3_unlock_req); out: + GF_FREE (req.dict.dict_val); gf_msg_debug ("glusterd", 0, "Returning %d", ret); return ret; } -- cgit