HIGH: Thread safety - cleanup() called from multiple threads without synchronization #4

Closed
opened 2026-09-07 15:00:49 +00:00 by x3 · 0 comments
Owner

Bug

cleanup() modified shared state (channel_, session_, fd fields) without any mutex. Called from both main thread (connect/disconnect) and IO thread.

Fix

Added std::mutex mutex_ and std::atomic<bool> cleanup_done_ to prevent concurrent cleanup:

void SshTerminal::cleanup() {
    std::lock_guard<std::mutex> lock(mutex_);
    if (cleanup_done_) return;
    cleanup_done_ = true;
    // ... cleanup resources
}

Status: Fixed in commit 4a2b2ea

## Bug `cleanup()` modified shared state (`channel_`, `session_`, fd fields) without any mutex. Called from both main thread (connect/disconnect) and IO thread. ## Fix Added `std::mutex mutex_` and `std::atomic<bool> cleanup_done_` to prevent concurrent cleanup: ```cpp void SshTerminal::cleanup() { std::lock_guard<std::mutex> lock(mutex_); if (cleanup_done_) return; cleanup_done_ = true; // ... cleanup resources } ``` **Status:** Fixed in commit 4a2b2ea
x3 closed this issue 2026-09-07 16:58:14 +00:00
Sign in to join this conversation.
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: x3/x3-ssh#4