diff --git a/HISTORY b/HISTORY index d8c2a437..4c0b5815 100644 --- a/HISTORY +++ b/HISTORY @@ -272,3 +272,6 @@ Issue #224 Update categories 19,20,21,23 2.8.7 (python_v0.7.6) Issue #232 When CAT48/250 is 0, no output is displayed + +2.8.7 (python_v0.7.7) +Issue #231 Memory leak in parse_with_offset python function \ No newline at end of file diff --git a/asterix/test/test_memory_leak.py b/asterix/test/test_memory_leak.py new file mode 100644 index 00000000..a2b5e277 --- /dev/null +++ b/asterix/test/test_memory_leak.py @@ -0,0 +1,20 @@ +# Test for memory leak problem in https://github.com/CroatiaControlLtd/asterix/issues/231 + +import asterix +from memory_profiler import profile + +@profile +def func(data): + p = asterix.parse_with_offset(data, 0, 100) + #p = asterix.parse(data) + #print(p) + +if __name__ == '__main__': + print(asterix.__version__) + + with open('../sample_data/cat062cat065.raw', 'rb') as f: + data = f.read() + + for i in range(10): + print('\n%d ------------------' % i) + func(data) \ No newline at end of file diff --git a/asterix/version.py b/asterix/version.py index 79866aba..b8308a14 100644 --- a/asterix/version.py +++ b/asterix/version.py @@ -1 +1 @@ -__version__ = '0.7.6' +__version__ = '0.7.7' diff --git a/src/python/python_parser.cpp b/src/python/python_parser.cpp index 9801290a..e38c5d2c 100644 --- a/src/python/python_parser.cpp +++ b/src/python/python_parser.cpp @@ -128,6 +128,9 @@ python_parse_with_offset(const unsigned char *pBuf, Py_ssize_t len, unsigned int delete pData; PyObject *py_m_nPos = Py_BuildValue("l", m_nPos); PyObject *py_output = PyTuple_Pack(2, lst, py_m_nPos); + // Decrease references since the tuple holds references to them now + Py_DECREF(lst); + Py_DECREF(py_m_nPos); return py_output; } }