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
if (disposing)
{
// Free managed objects.
- foreach (SmartcardReader reader in _readerList)
- {
- reader.Dispose();
- _readerList.Remove(reader);
- }
}
//Free unmanaged objects
deinitialize();
{
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)
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;
}
}
}
/// <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);
/// <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);