summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPranith Kumar K <pranithk@gluster.com>2010-09-02 07:06:47 +0000
committerVijay Bellur <vijay@dev.gluster.com>2010-09-02 06:31:41 -0700
commitee7f340f73eb2b61d5d1f6b881eede3b39432c9f (patch)
treedea647e1a9cba2e1a681befee9ad5ae6675c19ce
parent0d1199ecf08cb513db7bcd26db672811207fe5cf (diff)
mgmt/glusterd: memory leak fixes
Signed-off-by: Pranith Kumar K <pranithk@gluster.com> Signed-off-by: Vijay Bellur <vijay@dev.gluster.com> BUG: 1186 () URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=1186
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-handler.c21
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-op-sm.c61
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-sm.c51
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-sm.h5
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-utils.c2
-rw-r--r--xlators/mgmt/glusterd/src/glusterd3_1-mops.c11
6 files changed, 138 insertions, 13 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c
index c55de40b101..601546ba69f 100644
--- a/xlators/mgmt/glusterd/src/glusterd-handler.c
+++ b/xlators/mgmt/glusterd/src/glusterd-handler.c
@@ -392,7 +392,7 @@ glusterd_handle_cluster_lock (rpcsvc_request_t *req)
"Received LOCK from uuid: %s", str);
- ctx = GF_CALLOC (1, sizeof (*ctx), gf_gld_mt_op_stage_ctx_t);
+ ctx = GF_CALLOC (1, sizeof (*ctx), gf_gld_mt_op_lock_ctx_t);
if (!ctx) {
//respond here
@@ -1096,6 +1096,8 @@ glusterd_handle_create_volume (rpcsvc_request_t *req)
i++;
brick= strtok_r (brick_list, " \n", &tmpptr);
brick_list = tmpptr;
+ if (brickinfo)
+ glusterd_brickinfo_delete (brickinfo);
ret = glusterd_brickinfo_from_brick (brick, &brickinfo);
if (ret)
goto out;
@@ -1160,6 +1162,8 @@ out:
((ret || err_ret) != 0) ? "FAILED": "SUCCESS");
if (free_ptr)
GF_FREE(free_ptr);
+ if (brickinfo)
+ glusterd_brickinfo_delete (brickinfo);
return ret;
}
@@ -1358,6 +1362,8 @@ brick_val:
i++;
brick= strtok_r (brick_list, " \n", &tmpptr);
brick_list = tmpptr;
+ if (brickinfo)
+ glusterd_brickinfo_delete (brickinfo);
ret = glusterd_brickinfo_from_brick (brick, &brickinfo);
if (ret)
goto out;
@@ -1419,6 +1425,8 @@ out:
}
gf_cmd_log ("Volume add-brick","on volname %s %s", volname,
((ret || err_ret) != 0)? "FAILED" : "SUCCESS");
+ if (brickinfo)
+ glusterd_brickinfo_delete (brickinfo);
return ret;
}
@@ -1742,7 +1750,6 @@ glusterd_handle_log_locate (rpcsvc_request_t *req)
int32_t ret = -1;
gf1_cli_log_locate_req cli_req = {0,};
gf1_cli_log_locate_rsp rsp = {0,};
- dict_t *dict = NULL;
glusterd_conf_t *priv = NULL;
glusterd_volinfo_t *volinfo = NULL;
glusterd_brickinfo_t *brickinfo = NULL;
@@ -1761,10 +1768,6 @@ glusterd_handle_log_locate (rpcsvc_request_t *req)
gf_log ("glusterd", GF_LOG_NORMAL, "Received log locate req "
"for volume %s", cli_req.volname);
- dict = dict_new ();
- if (!dict)
- goto out;
-
if (strchr (cli_req.brick, ':')) {
/* TODO: need to get info of only that brick and then
tell what is the exact location */
@@ -2808,10 +2811,8 @@ glusterd_list_friends (rpcsvc_request_t *req, dict_t *dict, int32_t flags)
ret = 0;
out:
- if (ret) {
- if (friends)
- dict_unref (friends);
- }
+ if (friends)
+ dict_unref (friends);
rsp.op_ret = ret;
diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
index 330d8e6d2b2..fe3a3abd2d3 100644
--- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c
+++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
@@ -54,6 +54,36 @@ static struct list_head gd_op_sm_queue;
glusterd_op_info_t opinfo = {{0},};
static int glusterfs_port = GLUSTERD_DEFAULT_PORT;
+void
+glusterd_destroy_lock_ctx (glusterd_op_lock_ctx_t *ctx)
+{
+ if (!ctx)
+ return;
+ GF_FREE (ctx);
+}
+
+void
+glusterd_destroy_stage_ctx (glusterd_op_stage_ctx_t *ctx)
+{
+ if (!ctx)
+ return;
+
+ if (ctx->stage_req.buf.buf_val)
+ GF_FREE (ctx->stage_req.buf.buf_val);
+ GF_FREE (ctx);
+}
+
+void
+glusterd_destroy_commit_ctx (glusterd_op_commit_ctx_t *ctx)
+{
+ if (!ctx)
+ return;
+
+ if (ctx->stage_req.buf.buf_val)
+ GF_FREE (ctx->stage_req.buf.buf_val);
+ GF_FREE (ctx);
+}
+
static void
glusterd_set_volume_status (glusterd_volinfo_t *volinfo,
glusterd_volume_status status)
@@ -876,6 +906,8 @@ glusterd_op_stage_log_rotate (gd1_mgmt_stage_op_req *req)
}
out:
+ if (dict)
+ dict_unref (dict);
gf_log ("", GF_LOG_DEBUG, "Returning %d", ret);
return ret;
@@ -2372,6 +2404,8 @@ glusterd_op_log_filename (gd1_mgmt_stage_op_req *req)
ret = 0;
out:
+ if (dict)
+ dict_unref (dict);
return ret;
}
@@ -2478,6 +2512,8 @@ glusterd_op_log_rotate (gd1_mgmt_stage_op_req *req)
ret = 0;
out:
+ if (dict)
+ dict_unref (dict);
return ret;
}
@@ -3407,6 +3443,27 @@ out:
return ret;
}
+void
+glusterd_destroy_op_event_ctx (glusterd_op_sm_event_t *event)
+{
+ if (!event)
+ return;
+
+ switch (event->event) {
+ case GD_OP_EVENT_LOCK:
+ case GD_OP_EVENT_UNLOCK:
+ glusterd_destroy_lock_ctx (event->ctx);
+ break;
+ case GD_OP_EVENT_STAGE_OP:
+ glusterd_destroy_stage_ctx (event->ctx);
+ break;
+ case GD_OP_EVENT_COMMIT_OP:
+ glusterd_destroy_commit_ctx (event->ctx);
+ break;
+ default:
+ break;
+ }
+}
int
glusterd_op_sm ()
@@ -3438,6 +3495,7 @@ glusterd_op_sm ()
if (ret) {
gf_log ("glusterd", GF_LOG_ERROR,
"handler returned: %d", ret);
+ glusterd_destroy_op_event_ctx (event);
GF_FREE (event);
continue;
}
@@ -3454,6 +3512,7 @@ glusterd_op_sm ()
return ret;
}
+ glusterd_destroy_op_event_ctx (event);
GF_FREE (event);
}
}
@@ -3600,6 +3659,8 @@ glusterd_op_clear_ctx (glusterd_op_t op)
case GD_OP_ADD_BRICK:
case GD_OP_REMOVE_BRICK:
case GD_OP_REPLACE_BRICK:
+ case GD_OP_LOG_FILENAME:
+ case GD_OP_LOG_ROTATE:
dict_unref (ctx);
break;
case GD_OP_DELETE_VOLUME:
diff --git a/xlators/mgmt/glusterd/src/glusterd-sm.c b/xlators/mgmt/glusterd/src/glusterd-sm.c
index 3eaa8ffef30..2be2de4d203 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);
}
}
diff --git a/xlators/mgmt/glusterd/src/glusterd-sm.h b/xlators/mgmt/glusterd/src/glusterd-sm.h
index 6490f3d526d..2bd2601cbda 100644
--- a/xlators/mgmt/glusterd/src/glusterd-sm.h
+++ b/xlators/mgmt/glusterd/src/glusterd-sm.h
@@ -146,4 +146,9 @@ glusterd_friend_sm_init ();
int
glusterd_friend_sm ();
+void
+glusterd_destroy_probe_ctx (glusterd_probe_ctx_t *ctx);
+
+void
+glusterd_destroy_friend_req_ctx (glusterd_friend_req_ctx_t *ctx);
#endif
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
index 8ae2b03924c..4d9834adb33 100644
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
@@ -943,6 +943,8 @@ glusterd_peer_destroy (glusterd_peerinfo_t *peerinfo)
}
list_del_init (&peerinfo->hostnames);
+ if (peerinfo->hostname)
+ GF_FREE (peerinfo->hostname);
GF_FREE (peerinfo);
peerinfo = NULL;
diff --git a/xlators/mgmt/glusterd/src/glusterd3_1-mops.c b/xlators/mgmt/glusterd/src/glusterd3_1-mops.c
index 3f7db7e5b5c..0376f4be13e 100644
--- a/xlators/mgmt/glusterd/src/glusterd3_1-mops.c
+++ b/xlators/mgmt/glusterd/src/glusterd3_1-mops.c
@@ -93,8 +93,7 @@ glusterd3_1_probe_cbk (struct rpc_req *req, struct iovec *iov,
glusterd_peer_hostname_new (rsp.hostname, &name);
list_add_tail (&name->hostname_list, &peerinfo->hostnames);
peerinfo->rpc = dup_peerinfo->rpc;
- list_del_init (&dup_peerinfo->uuid_list);
- GF_FREE (dup_peerinfo);
+ glusterd_peer_destroy (dup_peerinfo);
}
if (!peerinfo->hostname)
peerinfo->hostname = gf_strdup (rsp.hostname);
@@ -111,6 +110,7 @@ glusterd3_1_probe_cbk (struct rpc_req *req, struct iovec *iov,
event->peerinfo = peerinfo;
event->ctx = ((call_frame_t *)myframe)->local;
+ ((call_frame_t *)myframe)->local = NULL;
ret = glusterd_friend_sm_inject_event (event);
@@ -203,6 +203,7 @@ glusterd3_1_friend_add_cbk (struct rpc_req * req, struct iovec *iov,
goto out;
ctx = ((call_frame_t *)myframe)->local;
+ ((call_frame_t *)myframe)->local = NULL;
GF_ASSERT (ctx);
@@ -212,7 +213,8 @@ glusterd3_1_friend_add_cbk (struct rpc_req * req, struct iovec *iov,
glusterd_friend_sm ();
glusterd_op_sm ();
}
-
+ if (ctx)
+ glusterd_destroy_probe_ctx (ctx);
out:
return ret;
}
@@ -236,6 +238,7 @@ glusterd3_1_friend_remove_cbk (struct rpc_req * req, struct iovec *iov,
GF_ASSERT (conf);
ctx = ((call_frame_t *)myframe)->local;
+ ((call_frame_t *)myframe)->local = NULL;
GF_ASSERT (ctx);
if (-1 == req->rpc_status) {
@@ -289,6 +292,8 @@ inject:
glusterd_friend_sm ();
glusterd_op_sm ();
+ if (ctx)
+ glusterd_destroy_probe_ctx (ctx);
op_ret = 0;