Skip to content

Commit 9388d10

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/+/235169 Well-Formed: Restriction Checker Tested-by: Trond Norbye <[email protected]> Reviewed-by: Faizan Alam <[email protected]>
1 parent 94b769f commit 9388d10

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
@@ -439,18 +439,20 @@ OrderedLL::iterator BasicLinkedList::purgeListElem(OrderedLL::iterator it,
439439

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

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

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

456458
BasicLinkedList::RangeIteratorLL::RangeIteratorLL(

0 commit comments

Comments
 (0)