Closed tspivey closed 1 year ago
There seems to be a memory leak while applying patches. Tested on 0.51.0 from PyPI and latest master (3b0a0a7ccd12355483a2a3efabf95e4dafe0d49a).
Test script:
from io import BytesIO import detools l = 50000000 data1 = b'a' * l data2 = b'b' * l patch = BytesIO() detools.create_patch(BytesIO(data1), BytesIO(data2), patch, compression='zstd', patch_type='hdiffpatch', algorithm='hdiffpatch', use_mmap=False) for i in range(50): new = BytesIO() print(i) patch.seek(0) detools.apply_patch(BytesIO(data1), patch, new)
On my system, this uses over 2 GB of memory once it completes (with python -i).
python -i
Adding free(temp_cache_p ); to the end of m_apply_patch in hdiffpatch.cpp reduces the usage to under 200 MB. Is this the correct solution?
free(temp_cache_p );
m_apply_patch
hdiffpatch.cpp
Yes, that looks like a bug and the free you suggest seems like a proper fix. Feel free to create a PR with the fix and I'll review and publish a new release once fixed.
There seems to be a memory leak while applying patches. Tested on 0.51.0 from PyPI and latest master (3b0a0a7ccd12355483a2a3efabf95e4dafe0d49a).
Test script:
On my system, this uses over 2 GB of memory once it completes (with
python -i
).Adding
free(temp_cache_p );
to the end ofm_apply_patch
inhdiffpatch.cpp
reduces the usage to under 200 MB. Is this the correct solution?