From c8460fceb5134be1e8300e60e44cb253371665e7 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Sun, 29 Oct 2023 15:39:14 -0700 Subject: [PATCH] [ntcore] Disable buf pool when asan is enabled This helps asan catch more errors. --- ntcore/src/main/native/cpp/net/WebSocketConnection.cpp | 4 ++++ ntcore/src/main/native/cpp/net3/UvStreamConnection3.cpp | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/ntcore/src/main/native/cpp/net/WebSocketConnection.cpp b/ntcore/src/main/native/cpp/net/WebSocketConnection.cpp index c5052195145..6cafcb054da 100644 --- a/ntcore/src/main/native/cpp/net/WebSocketConnection.cpp +++ b/ntcore/src/main/native/cpp/net/WebSocketConnection.cpp @@ -260,8 +260,12 @@ wpi::uv::Buffer WebSocketConnection::AllocBuf() { } void WebSocketConnection::ReleaseBufs(std::span 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(); } diff --git a/ntcore/src/main/native/cpp/net3/UvStreamConnection3.cpp b/ntcore/src/main/native/cpp/net3/UvStreamConnection3.cpp index a2f42d8da99..efc45348b07 100644 --- a/ntcore/src/main/native/cpp/net3/UvStreamConnection3.cpp +++ b/ntcore/src/main/native/cpp/net3/UvStreamConnection3.cpp @@ -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(); }