From 88551d8567503b3eba17e54fbe7dd9ee6266c1ab Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Mon, 10 Apr 2017 10:10:30 +0200 Subject: upcall: correct the cleanup path in init() when GF_CALLOC() fails Coverity found that "priv" can be NULL when the 1st GF_CALLOC() fails, and still is being used with "priv->xattrs" before the functon returns. While cleaning this up, also removing the log message for out of memory, as this is already logged through GF_CALLOC(). BUG: 789278 Change-Id: I887eaa9136dc25a39c107cd2152b1ba11f9fa925 Signed-off-by: Niels de Vos Reviewed-on: https://review.gluster.org/17023 Smoke: Gluster Build System NetBSD-regression: NetBSD Build System Reviewed-by: soumya k CentOS-regression: Gluster Build System Reviewed-by: Amar Tumballi --- xlators/features/upcall/src/upcall.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'xlators/features') diff --git a/xlators/features/upcall/src/upcall.c b/xlators/features/upcall/src/upcall.c index 40ad1c4e379..0e9919d41c4 100644 --- a/xlators/features/upcall/src/upcall.c +++ b/xlators/features/upcall/src/upcall.c @@ -2355,12 +2355,12 @@ init (xlator_t *this) priv = GF_CALLOC (1, sizeof (*priv), gf_upcall_mt_private_t); - if (!priv) { - gf_msg ("upcall", GF_LOG_WARNING, 0, - UPCALL_MSG_NO_MEMORY, - "Memory allocation failed"); + if (!priv) + goto out; + + priv->xattrs = dict_new (); + if (!priv->xattrs) goto out; - } GF_OPTION_INIT ("cache-invalidation", priv->cache_invalidation_enabled, bool, out); @@ -2369,12 +2369,11 @@ init (xlator_t *this) LOCK_INIT (&priv->inode_ctx_lk); INIT_LIST_HEAD (&priv->inode_ctx_list); - priv->xattrs = dict_new (); - this->private = priv; priv->fini = 0; priv->reaper_init_done = _gf_false; + this->private = priv; this->local_pool = mem_pool_new (upcall_local_t, 512); ret = 0; @@ -2391,8 +2390,10 @@ init (xlator_t *this) priv->reaper_init_done = _gf_true; } out: - if (ret) { - dict_unref (priv->xattrs); + if (ret && priv) { + if (priv->xattrs) + dict_unref (priv->xattrs); + GF_FREE (priv); } -- cgit