From 414d3e92fc56f08e320a3aa65b6b18e65b384551 Mon Sep 17 00:00:00 2001 From: N Balachandran Date: Thu, 24 Aug 2017 13:39:07 +0530 Subject: perf/qr: Use a ref-ed data to extract content qr_content_extract used dict_get to get the value of the GF_CONTENT_KEY key. dict_get does not ref the data before returning it so QR could be acting on freed memory if another thread deletes the key before then. This patch also fixes a race in dict_get_with_ref. Fix: Use dict_get_with_ref to retrieve the file contents. Change-Id: Ib1a7a70bb92eed7e70747ec530e0b3edc53127ec BUG: 1484709 Signed-off-by: N Balachandran Reviewed-on: https://review.gluster.org/18115 Smoke: Gluster Build System Reviewed-by: Amar Tumballi Tested-by: Raghavendra G CentOS-regression: Gluster Build System Reviewed-by: Raghavendra G --- libglusterfs/src/dict.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'libglusterfs/src/dict.c') diff --git a/libglusterfs/src/dict.c b/libglusterfs/src/dict.c index 22bf3f99d70..c4f3fb71de3 100644 --- a/libglusterfs/src/dict.c +++ b/libglusterfs/src/dict.c @@ -1433,7 +1433,7 @@ fail: */ -static int +int dict_get_with_ref (dict_t *this, char *key, data_t **data) { data_pair_t * pair = NULL; @@ -1453,14 +1453,13 @@ dict_get_with_ref (dict_t *this, char *key, data_t **data) LOCK (&this->lock); { pair = dict_lookup_common (this, key, hash); - } - UNLOCK (&this->lock); - if (pair) { - ret = 0; - *data = data_ref (pair->value); + if (pair) { + ret = 0; + *data = data_ref (pair->value); + } } - + UNLOCK (&this->lock); err: return ret; } -- cgit