Skip to content

Commit 7dab5b6

Browse files
committed
CBD-6348: [BP] clang-analyze: Refactor code to get rid of clang-warning
clang-analyzer with clang-15 reported a potential leak in engines/ep/src/linked_list.cc from create. This patch improves the readability of the code and as part of that clang-15 won't get fooled to report a potential leak. Change-Id: Icac67eb86f5adcccd3d924a3d9e15e46bfaf4c9e Reviewed-on: https://review.couchbase.org/c/kv_engine/+/234819 Well-Formed: Restriction Checker Reviewed-by: Jim Walker <[email protected]> Tested-by: Trond Norbye <[email protected]>
1 parent 5628257 commit 7dab5b6

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

engines/ep/src/linked_list.cc

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -438,18 +438,20 @@ OrderedLL::iterator BasicLinkedList::purgeListElem(OrderedLL::iterator it,
438438

439439
std::unique_ptr<BasicLinkedList::RangeIteratorLL>
440440
BasicLinkedList::RangeIteratorLL::create(BasicLinkedList& ll, bool isBackfill) {
441-
std::unique_ptr<BasicLinkedList::RangeIteratorLL> pRangeItr;
441+
std::unique_ptr<RangeIteratorLL> pRangeItr;
442442
{
443443
std::lock_guard<std::mutex> listWriteLg(ll.getListWriteLock());
444444

445445
/* Note: cannot use std::make_unique because the constructor of
446446
RangeIteratorLL is private */
447-
pRangeItr = std::unique_ptr<BasicLinkedList::RangeIteratorLL>(
448-
new BasicLinkedList::RangeIteratorLL(
449-
ll, listWriteLg, isBackfill));
447+
pRangeItr.reset(new RangeIteratorLL(ll, listWriteLg, isBackfill));
450448
}
451449

452-
return pRangeItr->tryLater() ? nullptr : std::move(pRangeItr);
450+
if (pRangeItr->tryLater()) {
451+
pRangeItr.reset();
452+
}
453+
454+
return pRangeItr;
453455
}
454456

455457
BasicLinkedList::RangeIteratorLL::RangeIteratorLL(

0 commit comments

Comments
 (0)