Skip to content

Commit

Permalink
[ntcore] Disable buf pool when asan is enabled
Browse files Browse the repository at this point in the history
This helps asan catch more errors.
  • Loading branch information
PeterJohnson committed Oct 29, 2023
1 parent 4464c3e commit c8460fc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ntcore/src/main/native/cpp/net/WebSocketConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,12 @@ wpi::uv::Buffer WebSocketConnection::AllocBuf() {
}

void WebSocketConnection::ReleaseBufs(std::span<wpi::uv::Buffer> bufs) {
#ifdef __SANITIZE_ADDRESS__
size_t numToPool = 0;
#else
size_t numToPool = (std::min)(bufs.size(), kMaxPoolSize - m_buf_pool.size());
m_buf_pool.insert(m_buf_pool.end(), bufs.begin(), bufs.begin() + numToPool);
#endif
for (auto&& buf : bufs.subspan(numToPool)) {
buf.Deallocate();
}
Expand Down
4 changes: 4 additions & 0 deletions ntcore/src/main/native/cpp/net3/UvStreamConnection3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,14 @@ void UvStreamConnection3::Flush() {
++m_sendsActive;
m_stream.Write(m_buffers, [selfweak = weak_from_this()](auto bufs, auto) {
if (auto self = selfweak.lock()) {
#ifdef __SANITIZE_ADDRESS__
size_t numToPool = 0;
#else
size_t numToPool =
(std::min)(bufs.size(), kMaxPoolSize - self->m_buf_pool.size());
self->m_buf_pool.insert(self->m_buf_pool.end(), bufs.begin(),
bufs.begin() + numToPool);
#endif
for (auto&& buf : bufs.subspan(numToPool)) {
buf.Deallocate();
}
Expand Down

0 comments on commit c8460fc

Please sign in to comment.