[NFC] Fix TC failed issue : the SEH exception occurs (#1327)
authorjh8801jung <jh8801.jung@samsung.com>
Mon, 3 Feb 2020 01:09:14 +0000 (10:09 +0900)
committerGitHub <noreply@github.com>
Mon, 3 Feb 2020 01:09:14 +0000 (10:09 +0900)
* [NFC] Fix TC failed issue : the SEH exception occurs

Signed-off-by: Jihoon Jung <jh8801.jung@samsung.com>
* Free IntPtr from capi

Signed-off-by: Jihoon Jung <jh8801.jung@samsung.com>
* Replace free method

Signed-off-by: Jihoon Jung <jh8801.jung@samsung.com>
src/Tizen.Network.Smartcard/Tizen.Network.Smartcard/SmartcardManagerImpl.cs
src/Tizen.Network.Smartcard/Tizen.Network.Smartcard/SmartcardSession.cs [changed mode: 0644->0755]

index 5e4db7f..4ee8f9c 100755 (executable)
@@ -29,7 +29,6 @@ namespace Tizen.Network.Smartcard
     internal class SmartcardManagerImpl : IDisposable
     {
         private static readonly SmartcardManagerImpl _instance = new SmartcardManagerImpl();
-        private List<SmartcardReader> _readerList = new List<SmartcardReader>();
         private bool disposed = false;
 
         internal static SmartcardManagerImpl Instance
@@ -64,11 +63,6 @@ namespace Tizen.Network.Smartcard
             if (disposing)
             {
                 // Free managed objects.
-                foreach (SmartcardReader reader in _readerList)
-                {
-                    reader.Dispose();
-                    _readerList.Remove(reader);
-                }
             }
             //Free unmanaged objects
             deinitialize();
@@ -98,6 +92,7 @@ namespace Tizen.Network.Smartcard
         {
             IntPtr readerPtr;
             int len = 0;
+            List<SmartcardReader> readerList = new List<SmartcardReader>();
 
             int ret = Interop.Smartcard.GetReaders(out readerPtr, out len);
             if (ret != (int)SmartcardError.None)
@@ -106,16 +101,22 @@ namespace Tizen.Network.Smartcard
                 SmartcardErrorFactory.ThrowSmartcardException(ret);
             }
 
+            IntPtr tempPtr = readerPtr;
             for (int i = 0; i < len; i++)
             {
-                int readerID = Marshal.ReadInt32(readerPtr);
+                int readerID = Marshal.ReadInt32(tempPtr);
 
                 SmartcardReader readerItem = new SmartcardReader(readerID);
-                _readerList.Add(readerItem);
-                readerPtr += sizeof(int);
+                readerList.Add(readerItem);
+                tempPtr += sizeof(int);
             }
 
-            return _readerList;
+            if (len > 0)
+            {
+                Interop.Libc.Free(readerPtr);
+            }
+
+            return readerList;
         }
     }
 }
old mode 100644 (file)
new mode 100755 (executable)
index 3467509..1d9d0e5
@@ -211,7 +211,8 @@ namespace Tizen.Network.Smartcard
         /// <exception cref="InvalidOperationException">Thrown when the method failed due to invalid operation.</exception>
         public SmartcardChannel OpenBasicChannel(byte[] aid, byte p2)
         {
-            int ret = Interop.Smartcard.Session.SessionOpenBasicChannel(_sessionHandle, aid, aid.Length, p2, out _basicChannel);
+            int aidLen = (aid == null ? 0 : aid.Length);
+            int ret = Interop.Smartcard.Session.SessionOpenBasicChannel(_sessionHandle, aid, aidLen, p2, out _basicChannel);
             if (ret != (int)SmartcardError.None)
             {
                 Log.Error(Globals.LogTag, "Failed to open basic channel, Error - " + (SmartcardError)ret);
@@ -234,7 +235,8 @@ namespace Tizen.Network.Smartcard
         /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
         public SmartcardChannel OpenLogicalChannel(byte[] aid, byte p2)
         {
-            int ret = Interop.Smartcard.Session.SessionOpenLogicalChannel(_sessionHandle, aid, aid.Length, p2, out _logicalChannel);
+            int aidLen = (aid == null ? 0 : aid.Length);
+            int ret = Interop.Smartcard.Session.SessionOpenLogicalChannel(_sessionHandle, aid, aidLen, p2, out _logicalChannel);
             if (ret != (int)SmartcardError.None)
             {
                 Log.Error(Globals.LogTag, "Failed to open logical channel, Error - " + (SmartcardError)ret);