Closed harmic closed 9 months ago
The problem is, if any error at all occurs,
self.inner
is not set toNone
,
Think a small typo in the description: should be self.inner
is now set to None
And the fix in what's already been merged is to not set to None
for the EAGAIN
case.
Anyway, shouldn't this issue be closed?
Anyway, shouldn't this issue be closed?
Yes, thank you for catching that.
I am using ssh2-rs together with async-ssh2 to make async sftp transfers.
I have been getting segfaults every so often. The stack trace looks like this:
In order to avoid blocking when dropping sftp file handles, I manually call
async_ssh2::File::close
, which in turn callsssh2::File::close
. That method currently looks like this:Looking in the source code for libssh2, you can see that if any error other than EAGAIN occurs, it goes ahead and deallocates the resources associated with the file. If you were to call it again after this you would get a crash.
In the comments it actually says:
The problem is, if any error at all occurs,
self.inner
is not set toNone
, which means later on when the struct is dropped,libssh2_sftp_close_handle
gets called again - which goes on to cause the segfault.The solution is to set self.inner to
None
either if no error occurs, OR if any error other than EAGAIN occurs.I will submit a PR containing a fix proposal.