From 178652106c5d731b24ddc9bb9bc1d8aae3952e2d Mon Sep 17 00:00:00 2001 From: Pranith Kumar K Date: Fri, 16 Mar 2012 11:35:36 +0530 Subject: glusterfsd: Handle errors in response send Change-Id: I2d0a136fdfc4c86fb89cff5565efbf4af80e1edf BUG: 799265 Signed-off-by: Pranith Kumar K Reviewed-on: http://review.gluster.com/2961 Tested-by: Gluster Build System Reviewed-by: Anand Avati --- glusterfsd/src/glusterfsd-mgmt.c | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) (limited to 'glusterfsd') diff --git a/glusterfsd/src/glusterfsd-mgmt.c b/glusterfsd/src/glusterfsd-mgmt.c index e45297d50d9..3b419262ac1 100644 --- a/glusterfsd/src/glusterfsd-mgmt.c +++ b/glusterfsd/src/glusterfsd-mgmt.c @@ -235,23 +235,28 @@ glusterfs_translator_info_response_send (rpcsvc_request_t *req, int ret, char *msg, dict_t *output) { gd1_mgmt_brick_op_rsp rsp = {0,}; - GF_ASSERT (msg); + gf_boolean_t free_ptr = _gf_false; GF_ASSERT (req); - GF_ASSERT (output); rsp.op_ret = ret; rsp.op_errno = 0; - if (ret && msg[0]) + if (ret && msg && msg[0]) rsp.op_errstr = msg; else rsp.op_errstr = ""; - ret = dict_allocate_and_serialize (output, &rsp.output.output_val, - (size_t *)&rsp.output.output_len); + ret = -1; + if (output) { + ret = dict_allocate_and_serialize (output, + &rsp.output.output_val, + (size_t *)&rsp.output.output_len); + } + if (!ret) + free_ptr = _gf_true; ret = glusterfs_submit_reply (req, &rsp, NULL, 0, NULL, (xdrproc_t)xdr_gd1_mgmt_brick_op_rsp); - if (rsp.output.output_val) + if (free_ptr) GF_FREE (rsp.output.output_val); return ret; } @@ -323,30 +328,28 @@ glusterfs_xlator_op_response_send (rpcsvc_request_t *req, int op_ret, { gd1_mgmt_brick_op_rsp rsp = {0,}; int ret = -1; - GF_ASSERT (msg); + gf_boolean_t free_ptr = _gf_false; GF_ASSERT (req); - GF_ASSERT (output); rsp.op_ret = op_ret; rsp.op_errno = 0; - if (ret && msg[0]) + if (op_ret && msg && msg[0]) rsp.op_errstr = msg; else rsp.op_errstr = ""; - ret = dict_allocate_and_serialize (output, &rsp.output.output_val, - (size_t *)&rsp.output.output_len); - if (ret) { - gf_log (THIS->name, GF_LOG_ERROR, "Couldn't serialize " - "output dict."); - goto out; + if (output) { + ret = dict_allocate_and_serialize (output, + &rsp.output.output_val, + (size_t *)&rsp.output.output_len); } + if (!ret) + free_ptr = _gf_true; ret = glusterfs_submit_reply (req, &rsp, NULL, 0, NULL, (xdrproc_t)xdr_gd1_mgmt_brick_op_rsp); -out: - if (rsp.output.output_val) + if (free_ptr) GF_FREE (rsp.output.output_val); return ret; -- cgit