This project is read-only.
1

Resolved

The SafeHandle was closed

description

Hi got following Exception when someone put up the phone with a little delay between ring and pickup.

_hCall.IsInvalid = true;

System.ObjectDisposedException was unhandled by user code
HResult=-2146232798
Message=Das SafeHandle wurde geschlossen.
Source=mscorlib
ObjectName=""
StackTrace:
   bei System.Runtime.InteropServices.SafeHandle.DangerousAddRef(Boolean& success)
   bei System.StubHelpers.StubHelpers.SafeHandleAddRef(SafeHandle pHandle, Boolean& success)
   bei JulMar.Atapi.Interop.NativeMethods.lineGetCallStatus(HTCALL hCall, IntPtr lpCallStatus)
   bei JulMar.Atapi.TapiCall.GatherCallStatus() in d:\Projekte\SanSoft.Team.2012\Lib\atapi\Atapi\trunk\source\src\TapiCall.cs:Zeile 2665.
   bei JulMar.Atapi.TapiCall.OnCallStateChange(Int32 callState, IntPtr stateData, MediaModes mediaModes) in d:\Projekte\SanSoft.Team.2012\Lib\atapi\Atapi\trunk\source\src\TapiCall.cs:Zeile 2633.
   bei JulMar.Atapi.TapiManager.ProcessTapiMessage(LINEMESSAGE msg) in d:\Projekte\SanSoft.Team.2012\Lib\atapi\Atapi\trunk\source\src\TapiManager.cs:Zeile 497.
   bei System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Object[]& outArgs)
   bei System.Runtime.Remoting.Messaging.StackBuilderSink.AsyncProcessMessage(IMessage msg, IMessageSink replySink)
InnerException:


The Source where the debugger shows is
    private void GatherCallStatus() //Class TapiCall
    {
        var lcs = new LINECALLSTATUS();
        int rc, neededSize = Marshal.SizeOf(lcs) + 100;
        do
        {
            lcs.dwTotalSize = neededSize;
            IntPtr pLcs = Marshal.AllocHGlobal(neededSize);
            Marshal.StructureToPtr(lcs, pLcs, true);
            rc = NativeMethods.lineGetCallStatus(_hCall, pLcs);  // here is the exception
            Marshal.PtrToStructure(pLcs, lcs);
            if (lcs.dwNeededSize > neededSize)
            {
                neededSize = lcs.dwNeededSize;
                rc = NativeMethods.LINEERR_STRUCTURETOOSMALL;
            }
            Marshal.FreeHGlobal(pLcs);
        }

comments

rum wrote Jan 10, 2013 at 8:02 AM

Hi, you're lucky.
I faced same issue a month ago, see issue 11472 and discussion 405378.

I also fixed it and committed a working patch. As it has not released yet, you should download and compile latest source. Otherwise, you just have to catch and ignore that Exception.

I'm going to close this issue, as duplicated.

wrote Jan 10, 2013 at 8:03 AM

AndyHoffmann wrote Jan 11, 2013 at 10:48 AM

Thanks, i use the last source from the svn repo

Now I Change the 'GatherCallStatus' function to, no crash anymore.

'Inline Code'
...
private object m_lockGatherCallStatus = new object();

    private void GatherCallStatus()
    {
        lock (m_lockGatherCallStatus)
        {
            if (_hCall.IsClosed)
            {
                Debug.Print("_hCall was closed");
                return;
            }

            var lcs = new LINECALLSTATUS();
            int rc, neededSize = Marshal.SizeOf(lcs) + 100;
            do
            {
                lcs.dwTotalSize = neededSize;
                IntPtr pLcs = Marshal.AllocHGlobal(neededSize);
                Marshal.StructureToPtr(lcs, pLcs, true);
                rc = NativeMethods.lineGetCallStatus(_hCall, pLcs);
                Marshal.PtrToStructure(pLcs, lcs);
                if (lcs.dwNeededSize > neededSize)
                {
                    neededSize = lcs.dwNeededSize;
                    rc = NativeMethods.LINEERR_STRUCTURETOOSMALL;
                }
                Marshal.FreeHGlobal(pLcs);
            }
            while (rc == NativeMethods.LINEERR_STRUCTURETOOSMALL);

            if (rc == NativeMethods.LINEERR_INVALCALLHANDLE)
            {
                Deallocate();
            }
            else
            {
                _callState = (CallState)lcs.dwCallState;
                _csTime = lcs.tStateEntryTime;
                _csPrivilege = (lcs.dwCallPrivilege == NativeMethods.LINECALLPRIVILEGE_NONE) ? Privilege.None :
                    (lcs.dwCallPrivilege == NativeMethods.LINECALLPRIVILEGE_MONITOR) ? Privilege.Monitor : Privilege.Owner;
                _features = new CallFeatureSet(lcs.dwCallFeatures);
            }
        }
    }
...

wrote Feb 14, 2013 at 8:41 PM

wrote May 16, 2013 at 10:56 AM

wrote May 16, 2013 at 10:56 AM

wrote Jun 14, 2013 at 8:20 AM

rperetz wrote Jun 5, 2014 at 6:51 PM

I am doing the following to place a call


private TapiCall PlaceCall(string formattedDestinationPhoneNumber)
    {
        try
        {
            if (mCurrentTapiLine.IsOpen)
            {
                mCurrentTapiLine.Close();

            }
            else
            {
                try
                {
                    mCurrentTapiLine.Open(mCurrentTapiLine.Capabilities.MediaModes);
                }
                catch (TapiException)
                {
                    mCurrentTapiLine.Open(MediaModes.DataModem);
                }
            }

            TapiCall tc = mCurrentTapiAddress.MakeCall(formattedDestinationPhoneNumber);
            return tc;
        }
        catch (TapiException ex)
        {
            throw ex;
        }

    }
and sometimes I get the same error, should I get the patch as well?

01:37:55|Error - Call for SourcePhoneNumber=1184 System.ObjectDisposedException: Safe handle has been closed
at System.Runtime.InteropServices.SafeHandle.DangerousAddRef(Boolean& success)
at System.StubHelpers.StubHelpers.SafeHandleAddRef(SafeHandle pHandle, Boolean& success)
at JulMar.Atapi.Interop.NativeMethods.lineGetCallStatus(HTCALL hCall, IntPtr lpCallStatus)
at JulMar.Atapi.TapiCall.GatherCallStatus()
at JulMar.Atapi.TapiCall..ctor(TapiAddress addrOwner, UInt32 hCall)
at JulMar.Atapi.TapiAddress.MakeCall(String address, Int32 countryCode, MakeCallParams param)
at ATAPIDialerHub.Dialer.PlaceCall(String formattedDestinationPhoneNumber)
at ATAPIDialerHub.Dialer.Call(String SourcePhoneNumber, String DestinationPhoneNumber, String officeLocation, String userLongDistanceCode)