Copilot commented on code in PR #3737:
URL: https://github.com/apache/brpc/pull/3737#discussion_r4537964769
##########
src/butil/object_pool_inl.h:
##########
@@ -459,10 +461,7 @@ class BAIDU_CACHELINE_ALIGNMENT ObjectPool {
// Create a Block and append it to right-most BlockGroup.
static Block* add_block(size_t* index) {
- Block* const new_block = new(std::nothrow) Block;
- if (nullptr == new_block) {
- return nullptr;
- }
+ auto const new_block = new Block;
Review Comment:
`add_block()` previously used `new(std::nothrow)` and returned `nullptr` on
allocation failure, but it now uses throwing `new Block`. This changes
behavior: on OOM it will throw `std::bad_alloc` (or terminate if exceptions are
disabled), and the function will no longer return `nullptr` as its
signature/logic implies. Please restore `new(std::nothrow) Block` (and keep the
nullptr check), or catch allocation failure and return `nullptr` to preserve
the existing failure contract.
##########
src/butil/object_pool_inl.h:
##########
@@ -497,13 +496,11 @@ class BAIDU_CACHELINE_ALIGNMENT ObjectPool {
return true;
}
if (ngroup < OP_MAX_BLOCK_NGROUP) {
- bg = new(std::nothrow) BlockGroup;
- if (nullptr != bg) {
- // Release fence is paired with consume fence in add_block()
- // to avoid un-constructed bg to be seen by other threads.
- _block_groups[ngroup].store(bg, butil::memory_order_release);
- _ngroup.store(ngroup + 1, butil::memory_order_release);
- }
+ bg = new BlockGroup;
+ // Release fence is paired with consume fence in add_block()
+ // to avoid un-constructed bg to be seen by other threads.
+ _block_groups[ngroup].store(bg, butil::memory_order_release);
+ _ngroup.store(ngroup + 1, butil::memory_order_release);
}
return bg != nullptr;
Review Comment:
`create_group()` now uses throwing `new BlockGroup`, but still returns `bg
!= nullptr` as if allocation could fail without an exception. With throwing
`new`, this return path won’t be reached on OOM (it will throw/terminate),
which is a behavioral change from the previous `new(std::nothrow)` handling.
Use `new(std::nothrow) BlockGroup` with the existing check, or handle
exceptions and return `false` on failure to keep the function’s semantics
consistent.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]