From ee7f340f73eb2b61d5d1f6b881eede3b39432c9f Mon Sep 17 00:00:00 2001 From: Pranith Kumar K Date: Thu, 2 Sep 2010 07:06:47 +0000 Subject: mgmt/glusterd: memory leak fixes Signed-off-by: Pranith Kumar K Signed-off-by: Vijay Bellur BUG: 1186 () URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=1186 --- xlators/mgmt/glusterd/src/glusterd-sm.c | 51 +++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'xlators/mgmt/glusterd/src/glusterd-sm.c') diff --git a/xlators/mgmt/glusterd/src/glusterd-sm.c b/xlators/mgmt/glusterd/src/glusterd-sm.c index 3eaa8ffef..2be2de4d2 100644 --- a/xlators/mgmt/glusterd/src/glusterd-sm.c +++ b/xlators/mgmt/glusterd/src/glusterd-sm.c @@ -46,6 +46,33 @@ static struct list_head gd_friend_sm_queue; +void +glusterd_destroy_probe_ctx (glusterd_probe_ctx_t *ctx) +{ + if (!ctx) + return; + + if (ctx->hostname) + GF_FREE (ctx->hostname); + GF_FREE (ctx); +} + +void +glusterd_destroy_friend_req_ctx (glusterd_friend_req_ctx_t *ctx) +{ + if (!ctx) + return; + + if (ctx->vols) + dict_unref (ctx->vols); + if (ctx->hostname) + GF_FREE (ctx->hostname); + GF_FREE (ctx); +} + +#define glusterd_destroy_friend_update_ctx(ctx)\ + glusterd_destroy_friend_req_ctx(ctx) + static int glusterd_ac_none (glusterd_friend_sm_event_t *event, void *ctx) { @@ -543,6 +570,27 @@ glusterd_friend_sm_inject_event (glusterd_friend_sm_event_t *event) return 0; } +void +glusterd_destroy_friend_event_context (glusterd_friend_sm_event_t *event) +{ + if (!event) + return; + + switch (event->event) { + case GD_FRIEND_EVENT_RCVD_FRIEND_REQ: + case GD_FRIEND_EVENT_RCVD_REMOVE_FRIEND: + glusterd_destroy_friend_req_ctx (event->ctx); + break; + case GD_FRIEND_EVENT_LOCAL_ACC: + case GD_FRIEND_EVENT_LOCAL_RJT: + case GD_FRIEND_EVENT_RCVD_ACC: + case GD_FRIEND_EVENT_RCVD_RJT: + glusterd_destroy_friend_update_ctx(event->ctx); + break; + default: + break; + } +} int glusterd_friend_sm () @@ -594,12 +642,14 @@ glusterd_friend_sm () if (ret) { gf_log ("glusterd", GF_LOG_ERROR, "handler returned: " "%d", ret); + glusterd_destroy_friend_event_context (event); GF_FREE (event); continue; } if ((GD_FRIEND_EVENT_REMOVE_FRIEND == event_type) || (GD_FRIEND_EVENT_INIT_REMOVE_FRIEND == event_type)){ + glusterd_destroy_friend_event_context (event); GF_FREE (event); continue; } @@ -615,6 +665,7 @@ glusterd_friend_sm () ret = glusterd_store_update_peerinfo (peerinfo); + glusterd_destroy_friend_event_context (event); GF_FREE (event); } } -- cgit