Skip to content

Commit

Permalink
Pool::Loan::get(): Return nullptr if has no item.
Browse files Browse the repository at this point in the history
Instead of deferencing the nullptr item.

Upstreaming change cl/308295787.
  • Loading branch information
ben-clayton committed Apr 24, 2020
1 parent 6c93413 commit ffa8828
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion include/marl/pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ T* Pool<T>::Loan::operator->() const {

template <typename T>
T* Pool<T>::Loan::get() const {
return item->get();
return item ? item->get() : nullptr;
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
10 changes: 10 additions & 0 deletions src/pool_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ TEST_P(WithBoundScheduler, BoundedPool_ConstructDestruct) {
marl::BoundedPool<int, 10> pool;
}

TEST_P(WithBoundScheduler, UnboundedPoolLoan_GetNull) {
marl::UnboundedPool<int>::Loan loan;
ASSERT_EQ(loan.get(), nullptr);
}

TEST_P(WithBoundScheduler, BoundedPoolLoan_GetNull) {
marl::BoundedPool<int, 10>::Loan loan;
ASSERT_EQ(loan.get(), nullptr);
}

TEST_P(WithBoundScheduler, UnboundedPool_Borrow) {
marl::UnboundedPool<int> pool;
for (int i = 0; i < 100; i++) {
Expand Down

0 comments on commit ffa8828

Please sign in to comment.