[Pcsclite-muscle] resource management in pyscard and python-pcsclite

Ludovic Rousseau ludovic.rousseau at gmail.com
Thu Dec 18 09:50:58 UTC 2014


Hello,

2014-12-17 22:23 GMT+01:00 Mark Kohler <mark.kohler at proteinsimple.com>:
> I've been using the smartcard.scard module, part of the pyscard package,
> and one thing that isn't clear to me is whether clients of
> smartcard.scard are reponsible for calling SCardReleaseContext and
> SCardDisconnect, in order to free the resources acquired by
> SCardEstablishContext and SCardConnect, respectively.
>
> I'm not 100% clear on the pcsclite architecture, but it seems to me
> that, with the pcsclite C API, it would be possible for a client
> application to cause leaks in the pcscd daemon, if the application does
> not call SCardReleaseContext and SCardDisconnect diligently.

It is always a good idea to explicitly call release functions.
If your code uses SCardEstablishContext then you have to also use
SCardReleaseContext.

If you have a use case that exhibits a memory leak in pcscd then please tell me.

> Assuming that is true, I'm wondering if it is also the case that
> applications using the smartcard.scard Python wrapper can cause similar
> leaks.

If such a leak exists in pcsc-lite: yes.
Python will not help solve a leak in pcscd if you use the low level pyscard API.

> The fact that the SCardEstablishContext and SCardConnect return
> integers, as opposed to a ref-counted object, also make me think that
> there is not any code that tells the Python garbage collector when and
> how to release PCSCD resources.
>
> Can anyone confirm this?

pcscd resources are not managed with the help (or not) of Python.

> By contrast, it appears that python-pcsclite library does use the Python
> garbage collector to automatically free PCSC resources. I believe that
> is the purpose of the Context_dealloc() and Card_dealloc() routines in
> pcsclite.c.
>
> Again, can anyone confirm this?

No idea. Maybe the python-pcsclite can anwser.

Bye

-- 
 Dr. Ludovic Rousseau



More information about the Pcsclite-muscle mailing list