Move IDisposable implementation declaration from inheritees to parent#746
Move IDisposable implementation declaration from inheritees to parent#746Rob-Hague merged 5 commits intosshnet:developfrom
Conversation
… AuthenticationMethod
|
Dispose pattern should be implemented in accordance with Implement a Dispose method to avoid code duplication. |
|
Hey @IgorMilavec, thanks for the feedback. |
IgorMilavec
left a comment
There was a problem hiding this comment.
Looks much cleaner now. Why not instantiate _authenticationCompleted in AuthenticationMethod's constructor? Also, do not declare finalizers, if they do not actually perform cleanup.
Because derived classes use different types for the EventWaitHandle : PrivateKeyAuthenticationMethod is using ManualResetEvent and the rest three are using AutoResetEvent.
Totally agree! Especially that classes with finalizers can take more time to dispose, so removing them is actaully small performance optimization. Updated code without finalizers on c34ad23. |
|
Huh, I totally missed different EventWaitHandles... I understand now. :) |
IgorMilavec
left a comment
There was a problem hiding this comment.
Looking good to me.
|
Pleasure doing business with you. Thanks |
# Conflicts: # src/Renci.SshNet/AuthenticationMethod.cs # src/Renci.SshNet/KeyboardInteractiveAuthenticationMethod.cs # src/Renci.SshNet/NoneAuthenticationMethod.cs # src/Renci.SshNet/PasswordAuthenticationMethod.cs # src/Renci.SshNet/PrivateKeyAuthenticationMethod.cs
Hello,
I was using SSH.NET library in my project and I noticed that by following inheritance rules I fell into a trap.
My SFTP wrapper class contains private field of a general AuthenticationMethod type.
It is is assigned in different constructors depending on selected authentication method.
When I was implementing Dispose() for SftpFileHandler I noticed that AuthenticationMethod does not require disposing which seemed a bit suspicious to me since it may contain sensitive data that may require proper disposing.
So I browsed descendants of AuthenticationMethod to discover that all 4 of them implement IDisposable interface.
That being said in other to properly dispose the whole SftpFileHandler I need to do something like:
Which is always true...
Instead of just simply:
I would like to propose a small improvement that would make disposing requirement move visible thus making it easier to maintain a little bit more secure code.
My suggestion is to move IDisposable a level above -> to the AuthenticationMethod:
This way code analyzing tools would warn programmers before making a mistake of not disposing inheritee of AuthenticationMethod class.
I tested changes mentioned above in my code and they work as expected.
What do you think about this improvement?