From 41f05fcefc1c192a3f322e827114897ec0ace316 Mon Sep 17 00:00:00 2001 From: Csaba Henk Date: Wed, 24 Mar 2010 14:01:36 +0000 Subject: Fix further cppcheck reported issues. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reported-by: Patrick Matthäi Signed-off-by: Csaba Henk Signed-off-by: Anand V. Avati BUG: 420 (fix leaks pointed out by cppcheck static analyzer) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=420 --- libglusterfs/src/dict.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'libglusterfs/src/dict.c') diff --git a/libglusterfs/src/dict.c b/libglusterfs/src/dict.c index b8728ac1306..9e97bf1d422 100644 --- a/libglusterfs/src/dict.c +++ b/libglusterfs/src/dict.c @@ -168,19 +168,32 @@ data_copy (data_t *old) if (old) { newdata->len = old->len; - if (old->data) + if (old->data) { newdata->data = memdup (old->data, old->len); - if (old->vec) + if (!newdata->data) + goto err_out; + } + if (old->vec) { newdata->vec = memdup (old->vec, old->len * (sizeof (void *) + sizeof (size_t))); - if (!old->data && !old->vec) { - gf_log ("dict", GF_LOG_CRITICAL, - "@newdata->data || @newdata->vec got NULL from CALLOC()"); - return NULL; + if (!newdata->vec) + goto err_out; } } return newdata; + + err_out: + + if (newdata->data) + FREE (newdata->data); + if (newdata->vec) + FREE (newdata->vec); + FREE (newdata); + + gf_log ("dict", GF_LOG_CRITICAL, + "@newdata->data || @newdata->vec got NULL from CALLOC()"); + return NULL; } static data_pair_t * @@ -248,6 +261,8 @@ _dict_set (dict_t *this, if (!pair->key) { gf_log ("dict", GF_LOG_CRITICAL, "@pair->key - NULL returned by CALLOC"); + FREE (pair); + return -1; } -- cgit