From 97bda86d41b3a60c01613e2e908ed9dbba738c6d Mon Sep 17 00:00:00 2001 From: Jakub Jelen Date: Fri, 15 Nov 2024 10:15:37 +0100 Subject: [PATCH] channels: Remove callbacks from freed channels When the user frees the channel, they no longer expect any callbacks to be triggered on it. When we delay the close before we receive the remaining messages, we should not trigger the user callbacks as it might be already freed. I believe this is the random torture_session test failures and errors we are getting from valgrind from time to time. We keep the callbacks cleanup in the do_cleanup() in case the calling application sets the callback after free for some reason. Signed-off-by: Jakub Jelen Reviewed-by: Andreas Schneider (cherry picked from commit 79ba546cde4bf5c8d5cdf7a73fd4767a125b1711) --- src/channels.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/channels.c b/src/channels.c index 72f44102..a10ac20d 100644 --- a/src/channels.c +++ b/src/channels.c @@ -1290,6 +1290,11 @@ void ssh_channel_free(ssh_channel channel) } channel->flags |= SSH_CHANNEL_FLAG_FREED_LOCAL; + if (channel->callbacks != NULL) { + ssh_list_free(channel->callbacks); + channel->callbacks = NULL; + } + /* The idea behind the flags is the following : it is well possible * that a client closes a channel that still exists on the server side. * We definitively close the channel when we receive a close message *and*