Skip to content
This repository was archived by the owner on Jan 26, 2026. It is now read-only.

Commit 32221ea

Browse files
committed
channels: Send close if we received a remote close
Signed-off-by: Andreas Schneider <asn@cryptomilk.org> (cherry picked from commit c3067f8)
1 parent 917ba07 commit 32221ea

1 file changed

Lines changed: 24 additions & 2 deletions

File tree

src/channels.c

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <stdio.h>
2929
#include <errno.h>
3030
#include <time.h>
31+
#include <stdbool.h>
3132

3233
#ifndef _WIN32
3334
#include <netinet/in.h>
@@ -1008,8 +1009,29 @@ void ssh_channel_free(ssh_channel channel)
10081009
}
10091010

10101011
session = channel->session;
1011-
if (session->alive && channel->state == SSH_CHANNEL_STATE_OPEN) {
1012-
ssh_channel_close(channel);
1012+
if (session->alive) {
1013+
bool send_close = false;
1014+
1015+
switch (channel->state) {
1016+
case SSH_CHANNEL_STATE_OPEN:
1017+
send_close = true;
1018+
break;
1019+
case SSH_CHANNEL_STATE_CLOSED:
1020+
if (channel->flags & SSH_CHANNEL_FLAG_CLOSED_REMOTE) {
1021+
send_close = true;
1022+
}
1023+
if (channel->flags & SSH_CHANNEL_FLAG_CLOSED_LOCAL) {
1024+
send_close = false;
1025+
}
1026+
break;
1027+
default:
1028+
send_close = false;
1029+
break;
1030+
}
1031+
1032+
if (send_close) {
1033+
ssh_channel_close(channel);
1034+
}
10131035
}
10141036
channel->flags |= SSH_CHANNEL_FLAG_FREED_LOCAL;
10151037

0 commit comments

Comments
 (0)