From db501c73701b620be67b4c33ea16cac983dcd9b1 Mon Sep 17 00:00:00 2001 From: Amar Tumballi Date: Sun, 25 Mar 2012 22:48:09 +0530 Subject: core: fix all the iobuf related refs and unrefs reviewed the code against all the possible places where iobuf/iobref ref unref are present, and hopefully fixed most of the issues around memory leaks with respect to iobuf Change-Id: I9aa30326962991f8e23acedd389a0e962e097885 Signed-off-by: Amar Tumballi BUG: 797875 Reviewed-on: http://review.gluster.com/2994 Tested-by: Gluster Build System Reviewed-by: Jeff Darcy Reviewed-by: Vijay Bellur --- xlators/nfs/server/src/nlm4.c | 12 ++- xlators/protocol/client/src/client-helpers.c | 2 +- xlators/protocol/client/src/client.c | 8 +- xlators/protocol/client/src/client3_1-fops.c | 129 +++++++++++++++++---------- 4 files changed, 98 insertions(+), 53 deletions(-) (limited to 'xlators') diff --git a/xlators/nfs/server/src/nlm4.c b/xlators/nfs/server/src/nlm4.c index 0aa1fc144..d73d1bce4 100644 --- a/xlators/nfs/server/src/nlm4.c +++ b/xlators/nfs/server/src/nlm4.c @@ -432,8 +432,6 @@ nlm4svc_submit_reply (rpcsvc_request_t *req, void *arg, nlm4_serializer sfunc) /* Then, submit the message for transmission. */ ret = rpcsvc_submit_message (req, &outmsg, 1, NULL, 0, iobref); - iobuf_unref (iob); - iobref_unref (iobref); if (ret == -1) { gf_log (GF_NLM, GF_LOG_ERROR, "Reply submission failed"); goto ret; @@ -441,6 +439,11 @@ nlm4svc_submit_reply (rpcsvc_request_t *req, void *arg, nlm4_serializer sfunc) ret = 0; ret: + if (iob) + iobuf_unref (iob); + if (iobref) + iobref_unref (iobref); + return ret; } @@ -1040,6 +1043,11 @@ nlm4svc_send_granted (nfs3_call_state_t *cs) goto ret; } ret: + if (iobref) + iobref_unref (iobref); + if (iobuf) + iobuf_unref (iobuf); + rpc_clnt_unref (rpc_clnt); nfs3_call_state_wipe (cs); return; diff --git a/xlators/protocol/client/src/client-helpers.c b/xlators/protocol/client/src/client-helpers.c index 8cf83fe30..3ee3bba53 100644 --- a/xlators/protocol/client/src/client-helpers.c +++ b/xlators/protocol/client/src/client-helpers.c @@ -141,7 +141,7 @@ client_local_wipe (clnt_local_t *local) iobref_unref (local->iobref); } - mem_put (local); + mem_put (local); } return 0; diff --git a/xlators/protocol/client/src/client.c b/xlators/protocol/client/src/client.c index 45d473fdb..9ce86b509 100644 --- a/xlators/protocol/client/src/client.c +++ b/xlators/protocol/client/src/client.c @@ -258,7 +258,7 @@ client_submit_request (xlator_t *this, void *req, call_frame_t *frame, ret = 0; - if (new_iobref != NULL) + if (new_iobref) iobref_unref (new_iobref); if (iobuf) @@ -271,11 +271,11 @@ out: cbkfn (&rpcreq, NULL, 0, frame); - if (new_iobref != NULL) { + if (new_iobref) iobref_unref (new_iobref); - } - iobuf_unref (iobuf); + if (iobuf) + iobuf_unref (iobuf); return 0; } diff --git a/xlators/protocol/client/src/client3_1-fops.c b/xlators/protocol/client/src/client3_1-fops.c index e1c144a8a..2cfa201ce 100644 --- a/xlators/protocol/client/src/client3_1-fops.c +++ b/xlators/protocol/client/src/client3_1-fops.c @@ -117,11 +117,11 @@ client_submit_vec_request (xlator_t *this, void *req, call_frame_t *frame, if (start_ping) client_start_ping ((void *) this); - if (new_iobref != NULL) { + if (new_iobref) iobref_unref (new_iobref); - } - iobuf_unref (iobuf); + if (iobuf) + iobuf_unref (iobuf); return ret; @@ -129,11 +129,11 @@ unwind: rpcreq.rpc_status = -1; cbkfn (&rpcreq, NULL, 0, frame); - if (new_iobref != NULL) { + if (new_iobref) iobref_unref (new_iobref); - } - iobuf_unref (iobuf); + if (iobuf) + iobuf_unref (iobuf); return ret; } @@ -2941,8 +2941,8 @@ client3_1_lookup (call_frame_t *frame, xlator_t *this, rsphdr->iov_base = iobuf_ptr (rsp_iobuf); rsphdr->iov_len = iobuf_pagesize (rsp_iobuf); count = 1; - rsp_iobuf = NULL; local->iobref = rsp_iobref; + rsp_iobuf = NULL; rsp_iobref = NULL; } @@ -2967,13 +2967,14 @@ client3_1_lookup (call_frame_t *frame, xlator_t *this, gf_log (this->name, GF_LOG_WARNING, "failed to send the fop"); } - if (req.xdata.xdata_val) { + if (req.xdata.xdata_val) GF_FREE (req.xdata.xdata_val); - } - if (rsp_iobref != NULL) { + if (rsp_iobref) iobref_unref (rsp_iobref); - } + + if (rsp_iobuf) + iobuf_unref (rsp_iobuf); return 0; @@ -2984,13 +2985,11 @@ unwind: if (req.xdata.xdata_val) GF_FREE (req.xdata.xdata_val); - if (rsp_iobref != NULL) { + if (rsp_iobref) iobref_unref (rsp_iobref); - } - if (rsp_iobuf != NULL) { + if (rsp_iobuf) iobuf_unref (rsp_iobuf); - } return 0; } @@ -3900,6 +3899,7 @@ client3_1_readv (call_frame_t *frame, xlator_t *this, iobref_add (rsp_iobref, rsp_iobuf); iobuf_unref (rsp_iobuf); + rsp_vec.iov_base = iobuf_ptr (rsp_iobuf); rsp_vec.iov_len = iobuf_pagesize (rsp_iobuf); @@ -3939,15 +3939,19 @@ client3_1_readv (call_frame_t *frame, xlator_t *this, if (req.xdata.xdata_val) GF_FREE (req.xdata.xdata_val); + if (rsp_iobuf) + iobuf_unref (rsp_iobuf); + + if (rsp_iobref) + iobref_unref (rsp_iobref); + return 0; unwind: - if (rsp_iobuf) { + if (rsp_iobuf) iobuf_unref (rsp_iobuf); - } - if (rsp_iobref) { + if (rsp_iobref) iobref_unref (rsp_iobref); - } CLIENT_STACK_UNWIND (readv, frame, -1, op_errno, NULL, 0, NULL, NULL, NULL); if (req.xdata.xdata_val) @@ -4516,12 +4520,13 @@ client3_1_fgetxattr (call_frame_t *frame, xlator_t *this, iobref_add (rsp_iobref, rsp_iobuf); iobuf_unref (rsp_iobuf); + rsphdr = &vector[0]; rsphdr->iov_base = iobuf_ptr (rsp_iobuf); rsphdr->iov_len = iobuf_pagesize (rsp_iobuf);; count = 1; - rsp_iobuf = NULL; local->iobref = rsp_iobref; + rsp_iobuf = NULL; rsp_iobref = NULL; req.namelen = 1; /* Use it as a flag */ @@ -4549,17 +4554,22 @@ client3_1_fgetxattr (call_frame_t *frame, xlator_t *this, if (req.xdata.xdata_val) GF_FREE (req.xdata.xdata_val); + if (rsp_iobuf) + iobuf_unref (rsp_iobuf); + + if (rsp_iobref) + iobref_unref (rsp_iobref); + return 0; unwind: CLIENT_STACK_UNWIND (fgetxattr, frame, -1, op_errno, NULL, NULL); - if (rsp_iobuf) { + if (rsp_iobuf) iobuf_unref (rsp_iobuf); - } - if (rsp_iobref) { + if (rsp_iobref) iobref_unref (rsp_iobref); - } + if (req.xdata.xdata_val) GF_FREE (req.xdata.xdata_val); @@ -4619,12 +4629,13 @@ client3_1_getxattr (call_frame_t *frame, xlator_t *this, iobref_add (rsp_iobref, rsp_iobuf); iobuf_unref (rsp_iobuf); + rsphdr = &vector[0]; rsphdr->iov_base = iobuf_ptr (rsp_iobuf); rsphdr->iov_len = iobuf_pagesize (rsp_iobuf); count = 1; - rsp_iobuf = NULL; local->iobref = rsp_iobref; + rsp_iobuf = NULL; rsp_iobref = NULL; if (!uuid_is_null (args->loc->inode->gfid)) @@ -4680,15 +4691,19 @@ client3_1_getxattr (call_frame_t *frame, xlator_t *this, if (req.xdata.xdata_val) GF_FREE (req.xdata.xdata_val); + if (rsp_iobuf) + iobuf_unref (rsp_iobuf); + + if (rsp_iobref) + iobref_unref (rsp_iobref); + return 0; unwind: - if (rsp_iobuf) { + if (rsp_iobuf) iobuf_unref (rsp_iobuf); - } - if (rsp_iobref) { + if (rsp_iobref) iobref_unref (rsp_iobref); - } CLIENT_STACK_UNWIND (getxattr, frame, op_ret, op_errno, dict, NULL); @@ -4746,12 +4761,13 @@ client3_1_xattrop (call_frame_t *frame, xlator_t *this, iobref_add (rsp_iobref, rsp_iobuf); iobuf_unref (rsp_iobuf); + rsphdr = &vector[0]; rsphdr->iov_base = iobuf_ptr (rsp_iobuf); rsphdr->iov_len = iobuf_pagesize (rsp_iobuf); count = 1; - rsp_iobuf = NULL; local->iobref = rsp_iobref; + rsp_iobuf = NULL; rsp_iobref = NULL; if (!uuid_is_null (args->loc->inode->gfid)) @@ -4792,6 +4808,12 @@ client3_1_xattrop (call_frame_t *frame, xlator_t *this, if (req.xdata.xdata_val) GF_FREE (req.xdata.xdata_val); + if (rsp_iobuf) + iobuf_unref (rsp_iobuf); + + if (rsp_iobref) + iobref_unref (rsp_iobref); + return 0; unwind: CLIENT_STACK_UNWIND (xattrop, frame, -1, op_errno, NULL, NULL); @@ -4800,13 +4822,12 @@ unwind: GF_FREE (req.dict.dict_val); } - if (rsp_iobuf) { + if (rsp_iobuf) iobuf_unref (rsp_iobuf); - } - if (rsp_iobref) { + if (rsp_iobref) iobref_unref (rsp_iobref); - } + if (req.xdata.xdata_val) GF_FREE (req.xdata.xdata_val); @@ -4870,8 +4891,8 @@ client3_1_fxattrop (call_frame_t *frame, xlator_t *this, rsphdr->iov_base = iobuf_ptr (rsp_iobuf); rsphdr->iov_len = iobuf_pagesize (rsp_iobuf); count = 1; - rsp_iobuf = NULL; local->iobref = rsp_iobref; + rsp_iobuf = NULL; rsp_iobref = NULL; if (args->xattr) { @@ -4900,6 +4921,12 @@ client3_1_fxattrop (call_frame_t *frame, xlator_t *this, if (req.xdata.xdata_val) GF_FREE (req.xdata.xdata_val); + if (rsp_iobuf) + iobuf_unref (rsp_iobuf); + + if (rsp_iobref) + iobref_unref (rsp_iobref); + return 0; unwind: CLIENT_STACK_UNWIND (fxattrop, frame, -1, op_errno, NULL, NULL); @@ -5488,12 +5515,14 @@ client3_1_readdir (call_frame_t *frame, xlator_t *this, iobref_add (rsp_iobref, rsp_iobuf); iobuf_unref (rsp_iobuf); + rsphdr = &vector[0]; rsphdr->iov_base = iobuf_ptr (rsp_iobuf); rsphdr->iov_len = iobuf_pagesize (rsp_iobuf); count = 1; - rsp_iobuf = NULL; local->iobref = rsp_iobref; + rsp_iobuf = NULL; + rsp_iobref = NULL; } req.size = args->size; @@ -5512,7 +5541,6 @@ client3_1_readdir (call_frame_t *frame, xlator_t *this, rsphdr, count, NULL, 0, rsp_iobref, (xdrproc_t)xdr_gfs3_readdir_req); - rsp_iobref = NULL; if (ret) { gf_log (this->name, GF_LOG_WARNING, "failed to send the fop"); @@ -5521,16 +5549,20 @@ client3_1_readdir (call_frame_t *frame, xlator_t *this, if (req.xdata.xdata_val) GF_FREE (req.xdata.xdata_val); + if (rsp_iobuf) + iobuf_unref (rsp_iobuf); + + if (rsp_iobref) + iobref_unref (rsp_iobref); + return 0; unwind: - if (rsp_iobref != NULL) { + if (rsp_iobref) iobref_unref (rsp_iobref); - } - if (rsp_iobuf != NULL) { + if (rsp_iobuf) iobuf_unref (rsp_iobuf); - } CLIENT_STACK_UNWIND (readdir, frame, -1, op_errno, NULL, NULL); if (req.xdata.xdata_val) @@ -5595,12 +5627,13 @@ client3_1_readdirp (call_frame_t *frame, xlator_t *this, iobref_add (rsp_iobref, rsp_iobuf); iobuf_unref (rsp_iobuf); + rsphdr = &vector[0]; rsphdr->iov_base = iobuf_ptr (rsp_iobuf); rsphdr->iov_len = iobuf_pagesize (rsp_iobuf); count = 1; - rsp_iobuf = NULL; local->iobref = rsp_iobref; + rsp_iobuf = NULL; rsp_iobref = NULL; } @@ -5628,15 +5661,19 @@ client3_1_readdirp (call_frame_t *frame, xlator_t *this, if (req.dict.dict_val) GF_FREE (req.dict.dict_val); + if (rsp_iobuf) + iobuf_unref (rsp_iobuf); + + if (rsp_iobref) + iobref_unref (rsp_iobref); + return 0; unwind: - if (rsp_iobref) { + if (rsp_iobref) iobref_unref (rsp_iobref); - } - if (rsp_iobuf) { + if (rsp_iobuf) iobuf_unref (rsp_iobuf); - } if (req.dict.dict_val) GF_FREE (req.dict.dict_val); -- cgit