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 <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit 79ba546cde)
This commit is contained in:
Jakub Jelen
2024-11-15 10:15:37 +01:00
parent 77c9498dbe
commit 97bda86d41

View File

@@ -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*