From b5e50cd714d105ff7aa1544182f07fb60320710d Mon Sep 17 00:00:00 2001 From: Pranith Kumar K Date: Fri, 6 Mar 2015 12:37:15 +0530 Subject: libxlator: Make sure marker_xattr is valid Problem: marker_xattr is allocated only when the op_ret is 0. If the final response is a failure, then the marker time is dict_set with key as NULL. this will be changed to ref: by dict_set, so the value won't appear on the marker-key when the getxattr_cbk is in dht. So dht unwinds with failure EINVAL. Fix: Always populate marker_xattr. Fixed dict mem-leak as well. Change-Id: I1752f277a8852c47b0a2ccce9fd72ee88456ac02 BUG: 1199406 Signed-off-by: Pranith Kumar K Reviewed-on: http://review.gluster.org/9817 Tested-by: Gluster Build System Reviewed-by: Raghavendra G Tested-by: Raghavendra G --- xlators/lib/src/libxlator.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/xlators/lib/src/libxlator.c b/xlators/lib/src/libxlator.c index 4e680c510ca..0b5036c8ba8 100644 --- a/xlators/lib/src/libxlator.c +++ b/xlators/lib/src/libxlator.c @@ -143,10 +143,10 @@ cluster_markerxtime_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int ret = -1; uint32_t *net_timebuf = NULL; uint32_t host_timebuf[2] = {0,}; - char *marker_xattr = NULL; + char marker_xattr[128] = {0}; xl_marker_local_t *local = NULL; - char *vol_uuid = NULL; char need_unwind = 0; + gf_boolean_t unref = _gf_false; if (!this || !frame || !frame->local || !cookie) { gf_log ("", GF_LOG_DEBUG, "possible NULL deref"); @@ -161,24 +161,18 @@ cluster_markerxtime_cbk (call_frame_t *frame, void *cookie, xlator_t *this, goto out; } + snprintf (marker_xattr, sizeof (marker_xattr), "%s.%s.%s", + MARKER_XATTR_PREFIX, local->vol_uuid, XTIME); + LOCK (&frame->lock); { callcnt = --local->call_count; - vol_uuid = local->vol_uuid; - if (op_ret) { marker_local_incr_errcount (local, op_errno); goto unlock; } - if (!gf_asprintf (&marker_xattr, "%s.%s.%s", - MARKER_XATTR_PREFIX, vol_uuid, XTIME)) { - op_errno = ENOMEM; - goto unlock; - } - - if (dict_get_ptr (dict, marker_xattr, (void **)&net_timebuf)) { gf_log (this->name, GF_LOG_WARNING, "Unable to get .xtime attr"); @@ -211,8 +205,16 @@ unlock: need_unwind = 1; if (local->count[MCNT_FOUND]) { - if (!dict) + if (!dict) { dict = dict_new(); + if (dict) { + unref = _gf_true; + } else { + op_ret = -1; + op_errno = ENOMEM; + goto out; + } + } ret = dict_set_static_bin (dict, marker_xattr, (void *)local->net_timebuf, 8); @@ -239,7 +241,9 @@ out: dict, xdata); } - GF_FREE (marker_xattr); + if (unref) + dict_unref (dict); + return 0; } -- cgit