From bfe2b5e1530efd364af7a175c8a1c89bc4cab0bb Mon Sep 17 00:00:00 2001 From: ShyamsundarR Date: Wed, 12 Dec 2018 16:45:09 -0500 Subject: clang: Fix various missing checks for empty list When using list_for_each_entry(_safe) functions, care needs to be taken that the list passed in are not empty, as these functions are not empty list safe. clag scan reported various points where this this pattern could be caught, and this patch fixes the same. Additionally the following changes are present in this patch, - Added an explicit op_ret setting in error case in the macro MAKE_INODE_HANDLE to address another clang issue reported - Minor refactoring of some functions in quota code, to address possible allocation failures in certain functions (which in turn cause possible empty lists to be passed around) Change-Id: I1e761a8d218708f714effb56fa643df2a3ea2cc7 Updates: bz#1622665 Signed-off-by: ShyamsundarR --- xlators/features/locks/src/posix.c | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) (limited to 'xlators/features/locks/src/posix.c') diff --git a/xlators/features/locks/src/posix.c b/xlators/features/locks/src/posix.c index ce6b6f9fbfc..2d7fd112c8d 100644 --- a/xlators/features/locks/src/posix.c +++ b/xlators/features/locks/src/posix.c @@ -2562,25 +2562,33 @@ pl_forget(xlator_t *this, inode_t *inode) } pthread_mutex_unlock(&pl_inode->mutex); - list_for_each_entry_safe(ext_l, ext_tmp, &posixlks_released, list) - { - STACK_UNWIND_STRICT(lk, ext_l->frame, -1, 0, &ext_l->user_flock, NULL); - __destroy_lock(ext_l); + if (!list_empty(&posixlks_released)) { + list_for_each_entry_safe(ext_l, ext_tmp, &posixlks_released, list) + { + STACK_UNWIND_STRICT(lk, ext_l->frame, -1, 0, &ext_l->user_flock, + NULL); + __destroy_lock(ext_l); + } } - list_for_each_entry_safe(ino_l, ino_tmp, &inodelks_released, blocked_locks) - { - STACK_UNWIND_STRICT(inodelk, ino_l->frame, -1, 0, NULL); - __pl_inodelk_unref(ino_l); + if (!list_empty(&inodelks_released)) { + list_for_each_entry_safe(ino_l, ino_tmp, &inodelks_released, + blocked_locks) + { + STACK_UNWIND_STRICT(inodelk, ino_l->frame, -1, 0, NULL); + __pl_inodelk_unref(ino_l); + } } - list_for_each_entry_safe(entry_l, entry_tmp, &entrylks_released, - blocked_locks) - { - STACK_UNWIND_STRICT(entrylk, entry_l->frame, -1, 0, NULL); - GF_FREE((char *)entry_l->basename); - GF_FREE(entry_l->connection_id); - GF_FREE(entry_l); + if (!list_empty(&entrylks_released)) { + list_for_each_entry_safe(entry_l, entry_tmp, &entrylks_released, + blocked_locks) + { + STACK_UNWIND_STRICT(entrylk, entry_l->frame, -1, 0, NULL); + GF_FREE((char *)entry_l->basename); + GF_FREE(entry_l->connection_id); + GF_FREE(entry_l); + } } pthread_mutex_destroy(&pl_inode->mutex); -- cgit