* Increment the reference counter on SafeHandle instances.
To prevent the common language runtime from reclaiming memory used by
a handle, this patch adds calling DangerousAddRef() before calling
DangerousGetHandle().
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
* Modify implementation of using SafeHandle
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
* Remove unnecesary blank line
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
{
Interop.LibRPCPort.Parcel.ReadBundle(_handle, out IntPtr b);
- return new Bundle(new SafeBundleHandle(b, true));
+ Bundle bundle = null;
+ using (SafeBundleHandle safeBundleHandle = new SafeBundleHandle(b, true))
+ {
+ bundle = new Bundle(safeBundleHandle);
+ }
+
+ return bundle;
}
/// <summary>
{
if (handle == null)
{
- throw new ArgumentNullException("handle");
+ throw new ArgumentNullException(nameof(handle));
}
- Interop.AppControl.ErrorCode err = Interop.AppControl.DangerousClone(out _handle, handle.DangerousGetHandle());
- if (err != Interop.AppControl.ErrorCode.None)
+ if (handle.IsInvalid)
{
- throw new InvalidOperationException("Failed to clone the appcontrol handle. Err = " + err);
+ throw new ArgumentNullException(nameof(handle), "handle is invalid");
+ }
+
+ bool mustRelease = false;
+ try
+ {
+ handle.DangerousAddRef(ref mustRelease);
+ Interop.AppControl.ErrorCode err = Interop.AppControl.DangerousClone(out _handle, handle.DangerousGetHandle());
+ if (err != Interop.AppControl.ErrorCode.None)
+ {
+ throw new InvalidOperationException("Failed to clone the appcontrol handle. Err = " + err);
+ }
+ }
+ catch (ObjectDisposedException e)
+ {
+ throw new ArgumentNullException(nameof(handle), e.Message);
+ }
+ finally
+ {
+ if (mustRelease)
+ {
+ handle.DangerousRelease();
+ }
}
}
{
if (handle == null)
{
- throw new ArgumentNullException("handle");
+ throw new ArgumentNullException(nameof(handle));
}
if (handle.IsInvalid)
{
- throw new ArgumentNullException("handle", "handle is invalid");
+ throw new ArgumentNullException(nameof(handle), "handle is invalid");
+ }
+
+ bool mustRelease = false;
+ try
+ {
+ handle.DangerousAddRef(ref mustRelease);
+ _handle = Interop.Bundle.DangerousClone(handle.DangerousGetHandle());
+ }
+ catch (ObjectDisposedException e)
+ {
+ throw new ArgumentNullException(nameof(handle), e.Message);
+ }
+ finally
+ {
+ if (mustRelease)
+ {
+ handle.DangerousRelease();
+ }
}
- _handle = Interop.Bundle.DangerousClone(handle.DangerousGetHandle());
_keys = new HashSet<string>();
Interop.Bundle.Iterator iterator = (string key, int type, IntPtr keyval, IntPtr userData) =>
{