Skip to content

Commit

Permalink
Python3: fix a memory leak in SCardGetStatusChange()
Browse files Browse the repository at this point in the history
The memory used to store the reader name in SCardGetStatusChange() was
leaking if Python 3 is used.

So SCardGetStatusChange() and any higher level method using
SCardGetStatusChange(), like CardMonitor(), was leaking memory.

Thanks to valdur55 for the bug report
"CardMonitor memory leak."
#37
  • Loading branch information
LudovicRousseau committed Feb 17, 2017
1 parent 7ad1cc2 commit 2c5f763
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions smartcard/scard/helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,6 @@ static int _ReaderStateFromTuple( PyObject* o, READERSTATELIST* prl, unsigned in
psz = PyBytes_AsString(temp_bytes); // Borrowed pointer
if (NULL == psz)
return 0;
psz = strdup(psz);
Py_DECREF(temp_bytes);
}
else
return 0;
Expand All @@ -133,6 +131,10 @@ static int _ReaderStateFromTuple( PyObject* o, READERSTATELIST* prl, unsigned in
prl->ars[x].szReader = prl->aszReaderNames[x];
strcpy( prl->aszReaderNames[x], psz );

#if PY_MAJOR_VERSION >= 3
Py_DECREF(temp_bytes);
#endif

// second tuple item is current state
o2=PyTuple_GetItem(o, 1);
prl->ars[x].dwCurrentState = (SCARDDWORDARG)PyInt_AsLong(o2);
Expand Down

0 comments on commit 2c5f763

Please sign in to comment.