Skip to content

Commit

Permalink
Fixed mempry leak in parse_with_offset
Browse files Browse the repository at this point in the history
  • Loading branch information
dsalantic committed Aug 23, 2024
1 parent 2336e2d commit cf38911
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
3 changes: 3 additions & 0 deletions HISTORY
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 20 additions & 0 deletions asterix/test/test_memory_leak.py
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion asterix/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.7.6'
__version__ = '0.7.7'
3 changes: 3 additions & 0 deletions src/python/python_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down

0 comments on commit cf38911

Please sign in to comment.