internal int Release()
        {
            int num2;

            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
            }
            finally
            {
                int num;
                num2 = Interlocked.Decrement(ref this._refCount);
                if (num2 != 0)
                {
                    goto Label_0168;
                }
                IntPtr hndlp = Interlocked.CompareExchange(ref this.handle, IntPtr.Zero, base.handle);
                if (!(IntPtr.Zero != hndlp))
                {
                    goto Label_0168;
                }
                OCI.HTYPE handleType   = this.HandleType;
                OciHandle parentHandle = this.ParentHandle;
                switch (handleType)
                {
                case OCI.HTYPE.OCI_HTYPE_ENV:
                    num = TracedNativeMethods.OCIHandleFree(hndlp, handleType);
                    if (num != 0)
                    {
                        throw System.Data.Common.ADP.OperationFailed("OCIHandleFree", num);
                    }
                    goto Label_015E;

                case OCI.HTYPE.OCI_HTYPE_ERROR:
                case OCI.HTYPE.OCI_HTYPE_STMT:
                case OCI.HTYPE.OCI_HTYPE_SESSION:
                    break;

                case OCI.HTYPE.OCI_HTYPE_SVCCTX:
                {
                    OciHandle handle2 = parentHandle;
                    if (handle2 != null)
                    {
                        OciHandle handle4 = handle2.ParentHandle;
                        if (handle4 != null)
                        {
                            OciHandle handle3 = handle4.ParentHandle;
                            if (handle3 != null)
                            {
                                num = TracedNativeMethods.OCISessionEnd(hndlp, handle3.DangerousGetHandle(), handle2.DangerousGetHandle(), OCI.MODE.OCI_DEFAULT);
                            }
                        }
                    }
                    break;
                }

                case OCI.HTYPE.OCI_HTYPE_SERVER:
                    TracedNativeMethods.OCIServerDetach(hndlp, parentHandle.DangerousGetHandle(), OCI.MODE.OCI_DEFAULT);
                    break;

                case OCI.HTYPE.OCI_DTYPE_FIRST:
                case OCI.HTYPE.OCI_DTYPE_ROWID:
                case OCI.HTYPE.OCI_DTYPE_FILE:
                case OCI.HTYPE.OCI_DTYPE_INTERVAL_DS:
                case OCI.HTYPE.OCI_DTYPE_TIMESTAMP:
                case OCI.HTYPE.OCI_DTYPE_TIMESTAMP_TZ:
                case OCI.HTYPE.OCI_DTYPE_TIMESTAMP_LTZ:
                    num = TracedNativeMethods.OCIDescriptorFree(hndlp, handleType);
                    if (num != 0)
                    {
                        throw System.Data.Common.ADP.OperationFailed("OCIDescriptorFree", num);
                    }
                    goto Label_015E;

                default:
                    goto Label_015E;
                }
                num = TracedNativeMethods.OCIHandleFree(hndlp, handleType);
                if (num != 0)
                {
                    throw System.Data.Common.ADP.OperationFailed("OCIHandleFree", num);
                }
Label_015E:
                if (parentHandle != null)
                {
                    parentHandle.Release();
                }
                Label_0168 :;
            }
            return(num2);
        }
Example #2
0
        private void Dispose(bool disposing)
        {
            HandleRef localHandle       = Handle;
            OciHandle localParentHandle = _parentOciHandle;

            try
            {
                try
                {
                    _parentOciHandle = null;
                    _handle          = IntPtr.Zero;
                }
                finally
                {
                    // BIND, DEFINE and PARAM handles cannot be freed; they go away automatically
                    // (but you'll have to ask Oracle how...)
                    if (OCI.HTYPE.OCI_HTYPE_BIND != _handleType &&
                        OCI.HTYPE.OCI_HTYPE_DEFINE != _handleType &&
                        OCI.HTYPE.OCI_DTYPE_PARAM != _handleType &&
                        IntPtr.Zero != localHandle.Handle &&
                        !_transacted)
                    {
                        if (_handleType == OCI.HTYPE.OCI_HTYPE_ENV || (null != localParentHandle && localParentHandle.IsAlive))
                        {
                            // DEVNOTE: the finalizer creates a race condition: it is possible
                            //          for both this handle and it's parent to be finalized
                            //          concurrently.  If the parent handle is freed before we
                            //          free this handle, Oracle will AV when we actually get
                            //          to free it.  We put a try/catch around this to avoid
                            //          the unhandled AV in the race condition, but we can't do
                            //          much about cdb, which always breaks on the AV because
                            //          it thinks its an unhandled exception, even though it's
                            //          being handled in managed code.
                            try
                            {
                                if (ExtraDispose(localHandle, _handleType))
                                {
                                    if (_handleType < OCI.HTYPE.OCI_DTYPE_FIRST)
                                    {
                                        TracedNativeMethods.OCIHandleFree(localHandle, _handleType);
                                    }
                                    else
                                    {
                                        TracedNativeMethods.OCIDescriptorFree(localHandle, _handleType);
                                    }
                                }
                            }
                            catch (NullReferenceException e)
                            {
                                ADP.TraceException(e);
                            }
                        }
                    }
                }
            }
            catch // Prevent exception filters from running in our space
            {
                throw;
            }
            GC.KeepAlive(this);
        }