[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: When it's safe to free callback userdata for channels and events?
[Thread Prev] | [Thread Next]
- Subject: Re: When it's safe to free callback userdata for channels and events?
- From: g4-lisz@xxxxxxxxxxxx
- Reply-to: libssh@xxxxxxxxxx
- Date: Mon, 4 Feb 2019 16:10:40 +0100
- To: libssh@xxxxxxxxxx
On 04.02.19 13:04, g4-lisz@xxxxxxxxxxxx wrote: > After one side has sent a EOF on a channel, I run ssh_channel_close() > and then test in the main event loop for ssh_channel_is_closed(). When > it's considered closed, I run ssh_channel_free(). > > Now the problem is that my_channel_data_function() is still called > after then channel has been closed and freed. Hence it's not possible > to free the userdata, because this would lead to unpredictable behaviour. > > So when exactly the channel callbacks are removed from the poll > context? And how can I check for this, so userdata can be freed safely? > After reading the channels.c source a bit more thoroughly I see where the problem is: Like ssh_channel_close() does not really close the channel, ssh_channel_free() also is no guarantee that the channel is really freed. In detail: The real, internal free function ssh_channel_do_free() (which also empties the callback list) is only called, when the channel is flagged as SSH_CHANNEL_FLAG_CLOSED_REMOTE or SSH_CHANNEL_FLAG_NOT_BOUND. I.e. as long as the peer doesn't send a "channel closed", the callbacks are still attached to the channel and the userdata can not be freed. This is not very convenient because in some cases the peer simply doesn't answer anymore, hence the channel will not be freed as long as the session is active. And the library doesn't export any method to force the freeing of a channel. There's no way to find out if the channel really has beend freed either. So right now we actually can never safely free the userdata ... Maybe ssh_channel_free() should rerturn an integer with 0= freed and 1= again i.e. still waiting for the peer? Regards, Till
When it's safe to free callback userdata for channels and events? | g4-lisz@xxxxxxxxxxxx |