Skip to content

Commit b5b96e7

Browse files
committed
fix(tests): leak-free teardown for the disconnect-cancel runtime test
LSan (Linux amd64 leg): 200 bytes — the runtime client (192) plus its IPC connection (8) — leaked whenever an earlier stage of daemon_runtime_disconnect_cancels_blocked_non_index_child... failed: both close blocks were gated on the request thread having completed, so a failed run skipped the close entirely. Teardown now closes unconditionally: close_begin interrupts the transport (forcing the blocked call to complete), the join becomes safe, and close_finish frees the client on every path. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent ad713bc commit b5b96e7

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

tests/test_daemon_runtime.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3648,8 +3648,25 @@ TEST(daemon_runtime_disconnect_cancels_blocked_non_index_child_and_preserves_oth
36483648
}
36493649
bool exited =
36503650
started && cbm_daemon_runtime_service_wait_exited(fixture.service, RUNTIME_TEST_TIMEOUT_MS);
3651-
if (first && !request_thread_started) {
3652-
(void)cbm_daemon_runtime_client_close(first, RUNTIME_TEST_TIMEOUT_MS);
3651+
/* Teardown must be leak-free on EVERY path, including the failure path
3652+
* where the request thread never completed: close_begin interrupts the
3653+
* transport, which forces the blocked call to finish, making the join
3654+
* safe; only close_finish releases the client. Skipping the close while
3655+
* the thread was still marked running leaked the client + its connection
3656+
* (LSan, 200 bytes) whenever an earlier stage of this test failed. */
3657+
if (first) {
3658+
if (!first_close_begun) {
3659+
first_close_begun = cbm_daemon_runtime_client_close_begin(first);
3660+
}
3661+
if (request_thread_started) {
3662+
(void)cbm_thread_join(&request_thread);
3663+
request_thread_started = false;
3664+
}
3665+
if (first_close_begun) {
3666+
(void)cbm_daemon_runtime_client_close_finish(first, RUNTIME_TEST_TIMEOUT_MS);
3667+
} else {
3668+
(void)cbm_daemon_runtime_client_close(first, RUNTIME_TEST_TIMEOUT_MS);
3669+
}
36533670
first = NULL;
36543671
}
36553672
runtime_test_fixture_finish(&fixture);

0 commit comments

Comments
 (0)