@@ -144,7 +144,6 @@ static struct Channel* newchannel(unsigned int remotechan,
144144 newchan -> index = i ;
145145 newchan -> sent_close = newchan -> recv_close = 0 ;
146146 newchan -> sent_eof = newchan -> recv_eof = 0 ;
147- newchan -> close_handler_done = 0 ;
148147
149148 newchan -> remotechan = remotechan ;
150149 newchan -> transwindow = transwindow ;
@@ -286,7 +285,7 @@ static void check_close(struct Channel *channel) {
286285 channel -> extrabuf ? cbuf_getused (channel -> extrabuf ) : 0 ))
287286
288287 if (!channel -> flushing
289- && !channel -> close_handler_done
288+ && !channel -> sent_close
290289 && channel -> type -> check_close
291290 && channel -> type -> check_close (channel ))
292291 {
@@ -298,7 +297,7 @@ static void check_close(struct Channel *channel) {
298297 channel, to ensure that the shell has exited (and the exit status
299298 retrieved) before we close things up. */
300299 if (!channel -> type -> check_close
301- || channel -> close_handler_done
300+ || channel -> sent_close
302301 || channel -> type -> check_close (channel )) {
303302 close_allowed = 1 ;
304303 }
@@ -385,10 +384,8 @@ void channel_connect_done(int result, int sock, void* user_data, const char* UNU
385384static void send_msg_channel_close (struct Channel * channel ) {
386385
387386 TRACE (("enter send_msg_channel_close %p" , (void * )channel ))
388- if (channel -> type -> closehandler
389- && !channel -> close_handler_done ) {
387+ if (channel -> type -> closehandler ) {
390388 channel -> type -> closehandler (channel );
391- channel -> close_handler_done = 1 ;
392389 }
393390
394391 CHECKCLEARTOWRITE ();
@@ -661,10 +658,8 @@ static void remove_channel(struct Channel * channel) {
661658 m_close (channel -> errfd );
662659 }
663660
664- if (!channel -> close_handler_done
665- && channel -> type -> closehandler ) {
666- channel -> type -> closehandler (channel );
667- channel -> close_handler_done = 1 ;
661+ if (channel -> type -> cleanup ) {
662+ channel -> type -> cleanup (channel );
668663 }
669664
670665 if (channel -> conn_pending ) {
@@ -690,13 +685,7 @@ void recv_msg_channel_request() {
690685
691686 TRACE (("enter recv_msg_channel_request %p" , (void * )channel ))
692687
693- if (channel -> sent_close ) {
694- TRACE (("leave recv_msg_channel_request: already closed channel" ))
695- return ;
696- }
697-
698- if (channel -> type -> reqhandler
699- && !channel -> close_handler_done ) {
688+ if (channel -> type -> reqhandler ) {
700689 channel -> type -> reqhandler (channel );
701690 } else {
702691 int wantreply ;
@@ -1011,6 +1000,11 @@ void recv_msg_channel_open() {
10111000void send_msg_channel_failure (const struct Channel * channel ) {
10121001
10131002 TRACE (("enter send_msg_channel_failure" ))
1003+
1004+ if (channel -> sent_close ) {
1005+ TRACE (("Skipping sending msg_channel_failure for closed channel" ))
1006+ return ;
1007+ }
10141008 CHECKCLEARTOWRITE ();
10151009
10161010 buf_putbyte (ses .writepayload , SSH_MSG_CHANNEL_FAILURE );
@@ -1024,6 +1018,10 @@ void send_msg_channel_failure(const struct Channel *channel) {
10241018void send_msg_channel_success (const struct Channel * channel ) {
10251019
10261020 TRACE (("enter send_msg_channel_success" ))
1021+ if (channel -> sent_close ) {
1022+ TRACE (("Skipping sending msg_channel_success for closed channel" ))
1023+ return ;
1024+ }
10271025 CHECKCLEARTOWRITE ();
10281026
10291027 buf_putbyte (ses .writepayload , SSH_MSG_CHANNEL_SUCCESS );
0 commit comments