diff options
author | Ludovic Henry <ludovic@xamarin.com> | 2016-02-16 23:46:23 +0300 |
---|---|---|
committer | Ludovic Henry <ludovic@xamarin.com> | 2016-02-17 13:54:49 +0300 |
commit | 920ec35630785d877f22aaf27099a1c6054af874 (patch) | |
tree | 132fa4703dcc8ec7b997f2340a9a139bd1a4c68b /mcs/class/corlib/System.Threading | |
parent | 8b36e3afb7b8c78462e30a8371b48e6849abbc3d (diff) |
[corlib] Fix potential RegisteredWaitHandle resource leak
If we construct RegisteredWaitHandle with executeOnlyOnce = true, and never call Unregister, we will keep _waitObject.SafeWaitHandle reference count unbalanced. This will lead to never releasing the waitObject handle.
As we only need to ensure that the waitObject handle is alive while in the Wait method, we use the SafeHandle mechanism only there. The 2 possibles scenarios in the Wait method are:
- waitObject has not been closed: we increment its ref count, so we ensure that it's alive as long as we use it here
- waitObject has been closed: a ObjectDisposedException is thrown, we catch it and keep on without trying to wait on the handle
Diffstat (limited to 'mcs/class/corlib/System.Threading')
-rw-r--r-- | mcs/class/corlib/System.Threading/RegisteredWaitHandle.cs | 5 |
1 files changed, 0 insertions, 5 deletions
diff --git a/mcs/class/corlib/System.Threading/RegisteredWaitHandle.cs b/mcs/class/corlib/System.Threading/RegisteredWaitHandle.cs index ec351ea66ed..1c8f4768d31 100644 --- a/mcs/class/corlib/System.Threading/RegisteredWaitHandle.cs +++ b/mcs/class/corlib/System.Threading/RegisteredWaitHandle.cs @@ -40,7 +40,6 @@ namespace System.Threading : MarshalByRefObject { WaitHandle _waitObject; - bool _releaseWaitObject; WaitOrTimerCallback _callback; object _state; WaitHandle _finalEvent; @@ -53,7 +52,6 @@ namespace System.Threading internal RegisteredWaitHandle (WaitHandle waitObject, WaitOrTimerCallback callback, object state, TimeSpan timeout, bool executeOnlyOnce) { _waitObject = waitObject; - _waitObject.SafeWaitHandle.DangerousAddRef (ref _releaseWaitObject); _callback = callback; _state = state; _timeout = timeout; @@ -122,9 +120,6 @@ namespace System.Threading if (_unregistered) return false; - if (_releaseWaitObject) - _waitObject.SafeWaitHandle.DangerousRelease (); - _finalEvent = waitObject; _unregistered = true; _cancelEvent.Set(); |