diff options
author | Max Kellermann <max@duempel.org> | 2014-12-14 15:56:53 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2014-12-14 16:02:47 +0100 |
commit | a543627abd19f321ddd4259e222e6437e8312417 (patch) | |
tree | 9a0494216cc13a0785d972f762c556c0718e3335 /src/lib/nfs/Connection.cxx | |
parent | 80f2ba7fca533de38575bdaf737ea89284ed2b7b (diff) | |
download | mpd-a543627abd19f321ddd4259e222e6437e8312417.tar.gz mpd-a543627abd19f321ddd4259e222e6437e8312417.tar.xz mpd-a543627abd19f321ddd4259e222e6437e8312417.zip |
lib/nfs/Connection: fix memory leak (and assertion failure)
nfs_destroy_context() will invoke all pending callbacks with
err==-EINTR. In CancellableCallback::Callback(), this will invoke
NfsConnection::DeferClose(), which however is only designed to be
called from nfs_service(). In non-debug mode, this will leak memory
because nfs_close_async() is never called.
Workaround: before nfs_destroy_context(), invoke nfs_close_async() on
all pending file handles.
Diffstat (limited to 'src/lib/nfs/Connection.cxx')
-rw-r--r-- | src/lib/nfs/Connection.cxx | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/lib/nfs/Connection.cxx b/src/lib/nfs/Connection.cxx index 48db620be..83b388dc4 100644 --- a/src/lib/nfs/Connection.cxx +++ b/src/lib/nfs/Connection.cxx @@ -133,6 +133,17 @@ NfsConnection::CancellableCallback::CancelAndScheduleClose(struct nfsfh *fh) } inline void +NfsConnection::CancellableCallback::PrepareDestroyContext() +{ + assert(IsCancelled()); + + if (close_fh != nullptr) { + connection.InternalClose(close_fh); + close_fh = nullptr; + } +} + +inline void NfsConnection::CancellableCallback::Callback(int err, void *data) { assert(connection.GetEventLoop().IsInside()); @@ -370,6 +381,10 @@ NfsConnection::DestroyContext() if (SocketMonitor::IsDefined()) SocketMonitor::Cancel(); + callbacks.ForEach([](CancellableCallback &c){ + c.PrepareDestroyContext(); + }); + nfs_destroy_context(context); context = nullptr; } |