mikaelliljedahl / freesftpsharp

SFTP server with Web Admin GUI based on FxSSH
MIT License
20 stars 3 forks source link

Make sure SftpSubsystem is disposed when channel is closed by removing event registrations #1

Closed mikaelliljedahl closed 3 years ago

mikaelliljedahl commented 3 years ago

SftpSubsystem instances are created in HostedServer inside InitializeSftp. At the same time these lines are called: channel.DataReceived += (ss, ee) => sftpsub.OnInput(ee); sftpsub.OnOutput += (ss, ee) => channel.SendData(ee); sftpsub.OnClose += (ss, ee) => channel.SendClose(null);

I assume adding event handlers without removing them when the channel is closed will prevent disposing the sftpsub references.

adding this and making sure CloseReceived is called from Channel should do it: channel.CloseReceived += (ss, ee) => { channel.DataReceived -= (ss, ee) => sftpsub.OnInput(ee); sftpsub.OnOutput -= (ss, ee) => channel.SendData(ee); sftpsub.OnClose -= (ss, ee) => channel.SendClose(null); sftpsub.Dispose(); // is this needed? It will force all open file handles to be released }; };

mikaelliljedahl commented 3 years ago

Fixed in this commit: https://github.com/mikaelliljedahl/freesftpsharp/commit/a088bfe6c29cbe03f842c4d3a1a4676c7487eb88