From 927aedbb556ee07250248181f52642eeb6de9e58 Mon Sep 17 00:00:00 2001 From: Amar Tumballi Date: Wed, 28 Jul 2010 03:31:10 +0000 Subject: removed last few remaining 'ERR_ABORT's from codebase Signed-off-by: Amar Tumballi Signed-off-by: Anand V. Avati BUG: 966 (NULL check for avoiding NULL dereferencing of pointers..) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=966 --- xlators/features/locks/src/common.c | 80 +++++++++++++++++++++++++++---------- 1 file changed, 58 insertions(+), 22 deletions(-) (limited to 'xlators/features/locks/src/common.c') diff --git a/xlators/features/locks/src/common.c b/xlators/features/locks/src/common.c index 2ba8df002..b34cd9781 100644 --- a/xlators/features/locks/src/common.c +++ b/xlators/features/locks/src/common.c @@ -590,70 +590,106 @@ struct _values { static struct _values subtract_locks (posix_lock_t *big, posix_lock_t *small) { + struct _values v = { .locks = {0, 0, 0} }; - - if ((big->fl_start == small->fl_start) && - (big->fl_end == small->fl_end)) { + + if ((big->fl_start == small->fl_start) && + (big->fl_end == small->fl_end)) { /* both edges coincide with big */ v.locks[0] = GF_CALLOC (1, sizeof (posix_lock_t), gf_locks_mt_posix_lock_t); - ERR_ABORT (v.locks[0]); + if (!v.locks[0]) + goto out; memcpy (v.locks[0], big, sizeof (posix_lock_t)); v.locks[0]->fl_type = small->fl_type; + goto done; } - else if ((small->fl_start > big->fl_start) && - (small->fl_end < big->fl_end)) { + + if ((small->fl_start > big->fl_start) && + (small->fl_end < big->fl_end)) { /* both edges lie inside big */ v.locks[0] = GF_CALLOC (1, sizeof (posix_lock_t), gf_locks_mt_posix_lock_t); - ERR_ABORT (v.locks[0]); + if (!v.locks[0]) + goto out; + v.locks[1] = GF_CALLOC (1, sizeof (posix_lock_t), gf_locks_mt_posix_lock_t); - ERR_ABORT (v.locks[1]); + if (!v.locks[1]) + goto out; + v.locks[2] = GF_CALLOC (1, sizeof (posix_lock_t), gf_locks_mt_posix_lock_t); - ERR_ABORT (v.locks[2]); + if (!v.locks[1]) + goto out; memcpy (v.locks[0], big, sizeof (posix_lock_t)); v.locks[0]->fl_end = small->fl_start - 1; memcpy (v.locks[1], small, sizeof (posix_lock_t)); + memcpy (v.locks[2], big, sizeof (posix_lock_t)); v.locks[2]->fl_start = small->fl_end + 1; + goto done; + } + /* one edge coincides with big */ - else if (small->fl_start == big->fl_start) { + if (small->fl_start == big->fl_start) { v.locks[0] = GF_CALLOC (1, sizeof (posix_lock_t), gf_locks_mt_posix_lock_t); - ERR_ABORT (v.locks[0]); + if (!v.locks[0]) + goto out; + v.locks[1] = GF_CALLOC (1, sizeof (posix_lock_t), gf_locks_mt_posix_lock_t); - ERR_ABORT (v.locks[1]); - + if (!v.locks[1]) + goto out; + memcpy (v.locks[0], big, sizeof (posix_lock_t)); v.locks[0]->fl_start = small->fl_end + 1; - + memcpy (v.locks[1], small, sizeof (posix_lock_t)); + goto done; } - else if (small->fl_end == big->fl_end) { + + if (small->fl_end == big->fl_end) { v.locks[0] = GF_CALLOC (1, sizeof (posix_lock_t), gf_locks_mt_posix_lock_t); - ERR_ABORT (v.locks[0]); + if (!v.locks[0]) + goto out; + v.locks[1] = GF_CALLOC (1, sizeof (posix_lock_t), gf_locks_mt_posix_lock_t); - ERR_ABORT (v.locks[1]); + if (!v.locks[1]) + goto out; memcpy (v.locks[0], big, sizeof (posix_lock_t)); v.locks[0]->fl_end = small->fl_start - 1; - + memcpy (v.locks[1], small, sizeof (posix_lock_t)); + goto done; } - else { - gf_log ("posix-locks", GF_LOG_ERROR, - "Unexpected case in subtract_locks. Please send " - "a bug report to gluster-devel@nongnu.org"); + + gf_log ("posix-locks", GF_LOG_ERROR, + "Unexpected case in subtract_locks. Please send " + "a bug report to gluster-devel@nongnu.org"); + +out: + if (v.locks[0]) { + GF_FREE (v.locks[0]); + v.locks[0] = NULL; + } + if (v.locks[1]) { + GF_FREE (v.locks[1]); + v.locks[1] = NULL; + } + if (v.locks[2]) { + GF_FREE (v.locks[2]); + v.locks[2] = NULL; } +done: return v; } -- cgit