Skip to content

Commit 73674af

Browse files
committed
fix: enhance del_stream function with debug logging and early return for uninitialized hash table
Signed-off-by: Dengfeng Liu <[email protected]>
1 parent c04cbc8 commit 73674af

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

tcpmux.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,25 @@ void add_stream(struct tmux_stream *stream) {
6767
* @param id The ID of the stream to be deleted.
6868
*/
6969
void del_stream(uint32_t id) {
70-
if (!all_stream)
70+
// Early return if hash table is not initialized
71+
if (!all_stream) {
72+
debug(LOG_DEBUG, "Stream hash table not initialized");
7173
return;
74+
}
75+
76+
// Find stream in hash table
77+
struct tmux_stream *stream = NULL;
78+
HASH_FIND_INT(all_stream, &id, stream);
7279

73-
struct tmux_stream *stream = get_stream_by_id(id);
74-
if (stream)
75-
HASH_DEL(all_stream, stream); // no need to free stream, it will be freed
76-
// when proxy client is freed
80+
// Delete stream if found
81+
if (stream) {
82+
HASH_DEL(all_stream, stream);
83+
debug(LOG_DEBUG, "Stream %u removed from hash table", id);
84+
} else {
85+
debug(LOG_DEBUG, "Stream %u not found in hash table", id);
86+
}
87+
88+
// Note: Stream memory is freed when associated proxy client is freed
7789
}
7890

7991
/**

0 commit comments

Comments
 (0)