aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/nfs/FileReader.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-09-26 13:29:44 +0200
committerMax Kellermann <max@duempel.org>2014-10-01 23:10:32 +0200
commit0661fd6f7c66ae888b6fc253af6dd0514798eff5 (patch)
tree9cc213a9d3be7709f937df4cfb40255d74146338 /src/lib/nfs/FileReader.cxx
parentedd003b62af802fae7828336628adb0ea3f6bd21 (diff)
downloadmpd-0661fd6f7c66ae888b6fc253af6dd0514798eff5.tar.gz
mpd-0661fd6f7c66ae888b6fc253af6dd0514798eff5.tar.xz
mpd-0661fd6f7c66ae888b6fc253af6dd0514798eff5.zip
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().
Diffstat (limited to 'src/lib/nfs/FileReader.cxx')
-rw-r--r--src/lib/nfs/FileReader.cxx15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/lib/nfs/FileReader.cxx b/src/lib/nfs/FileReader.cxx
index 52d951fa6..d2be46f8e 100644
--- a/src/lib/nfs/FileReader.cxx
+++ b/src/lib/nfs/FileReader.cxx
@@ -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;
}