Skip to content

Support LSan in UT#56

Open
chenBright wants to merge 1 commit into
masterfrom
lsan
Open

Support LSan in UT#56
chenBright wants to merge 1 commit into
masterfrom
lsan

Conversation

@chenBright

Copy link
Copy Markdown
Owner

What problem does this PR solve?

Issue Number: resolve

Problem Summary:

What is changed and the side effects?

Changed:

Side effects:

  • Performance effects:

  • Breaking backward compatibility:


Check List:

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to make the unit-test suite LeakSanitizer-friendly by eliminating real leaks in tests, adding targeted leak annotations for intentional process-lifetime allocations, and introducing an LSan suppressions file for unavoidable third‑party allocations.

Changes:

  • Fixes multiple unit-test leaks by tightening ownership/lifetimes (e.g., RAII with unique_ptr, freeing buffers, releasing TLS blocks, deleting test-created objects).
  • Adds LSan/ASan configuration for test runs (LSAN_OPTIONS + ASAN_OPTIONS) and introduces test/lsan_suppressions.txt.
  • Adds/adjusts LSan leak-annotation usage in core runtime paths (logging, thread-local caches, long-lived bthreads) and cleans up RDMA block pool teardown.

Reviewed changes

Copilot reviewed 24 out of 24 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
test/thread_key_unittest.cpp Keeps per-key data owned in the test to avoid LSan-reported leaks when keys are deleted.
test/run_tests.sh Enables leak detection and points LSan at the suppressions file for UT runs.
test/object_pool_unittest.cpp Avoids leaking new int allocations by freeing outside the timed region.
test/lsan_suppressions.txt Adds suppressions for known third-party, process-lifetime allocations (gperftools).
test/iobuf_unittest.cpp Releases acquired TLS block back to TLS to avoid leaking it.
test/CMakeLists.txt Copies the LSan suppressions file into the test binary directory.
test/bthread_dispatcher_unittest.cpp Ensures epoll thread can exit and frees/cleans up allocated test resources.
test/brpc_socket_unittest.cpp Marks intentional leaks, fixes self-destruction behavior, and frees buffers on exit paths.
test/brpc_redis_unittest.cpp Uses RAII for handlers/authenticator to prevent leaks in Redis UT.
test/brpc_redis_cluster_unittest.cpp Makes RedisService handler ownership explicit via unique_ptr members.
test/brpc_protobuf_json_unittest.cpp Replaces heap allocation with stack buffer to avoid a leak.
test/brpc_proto_unittest.cpp Uses unique_ptr for dynamically allocated protobuf Message.
test/brpc_load_balancer_unittest.cpp Avoids leaking SocketOptions.user and deletes a heap-allocated load balancer.
test/brpc_input_messenger_unittest.cpp Frees per-thread buffers and deletes allocated client metadata.
test/brpc_event_dispatcher_unittest.cpp Adds cleanup for socket user buffers and releases per-client allocations.
src/butil/logging.cc Reduces retained string capacity under ASan and annotates async logging path for LSan.
src/butil/lazy_instance.h Removes an include dependency while keeping leak annotations available.
src/butil/find_cstr.h Annotates thread-local cache allocations to avoid false-positive leak reports.
src/butil/debug/leak_annotations.h Adds explicit disable/enable helpers and updates the annotation interface.
src/brpc/socket_map.cpp Adds leak-annotation usage in WatchConnections and documents intent.
src/brpc/server.cpp Narrows scoped leak annotation to the intended initialization region.
src/brpc/rdma/block_pool.cpp Frees mutexes and other globals during RDMA block pool destruction.
src/brpc/global.cpp Disables LSan only around intentional process-lifetime constructions in GlobalUpdate.
.github/workflows/ci-linux.yml Adjusts Bazel test defines used in CI.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/brpc/socket_map.cpp Outdated
Comment thread src/brpc/socket_map.cpp
@chenBright chenBright force-pushed the lsan branch 5 times, most recently from a765829 to a01946c Compare June 22, 2026 11:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants