lib/nfs/FileReader: postpone the nfs_close_async() call

If an async opertion is in progress, nfs_close_async() will make
libnfs crash because the RPC callback will dereference an object that
was freed by nfs_close_async().
This commit is contained in:
Max Kellermann
2014-09-26 13:29:44 +02:00
parent edd003b62a
commit 0661fd6f7c
4 changed files with 92 additions and 6 deletions

View File

@@ -57,11 +57,18 @@ NfsFileReader::Close()
connection->RemoveLease(*this);
if (state > State::MOUNT && state != State::IDLE)
connection->Cancel(*this);
if (state > State::OPEN)
if (state == State::IDLE)
/* no async operation in progress: can close
immediately */
connection->Close(fh);
else if (state > State::OPEN)
/* one async operation in progress: cancel it and
defer the nfs_close_async() call */
connection->CancelAndClose(fh, *this);
else if (state > State::MOUNT)
/* we don't have a file handle yet - just cancel the
async operation */
connection->Cancel(*this);
state = State::INITIAL;
}