naihe2010/apvlv — pull request #11 by DarkStarSword (2012-10-12 06:10:06+00:00)
Title: Fix some memory leaks in ApvlvPDF::pagesearch

apvlv was leaking memory in the pagesearch function. Since I tend to
search 1500+ page documents regularly I would pretty quickly run out of
memory and my system would start thrashing.

This patch adds the appropriate unref & free calls to avoid this
particular memory leak.

Testcase:
1. Configure apvlv with cmake -D CMAKE_BUILD_TYPE=DEBUG
2. Optionally start htop in another window to observe the memory blowout
3. valgrind --error-limit=no --leak-check=full apvlv very_large_document.pdf
4. Search for a string that does not exist in the document
5. Close apvlv and read valgrind summary

Before (Note almost 1/2 GB memory is listed as possibly lost)
==14302== LEAK SUMMARY:
==14302== definitely lost: 4,430 bytes in 9 blocks
==14302== indirectly lost: 11,392 bytes in 354 blocks
==14302== possibly lost: 562,418,510 bytes in 3,798,367 blocks
==14302== still reachable: 1,704,596 bytes in 13,324 blocks

After (down to 16M possibly lost):
==22458== LEAK SUMMARY:
==22458== definitely lost: 4,416 bytes in 8 blocks
==22458== indirectly lost: 11,392 bytes in 354 blocks
==22458== possibly lost: 16,820,645 bytes in 149,355 blocks
==22458== still reachable: 3,892,602 bytes in 9,368 blocks

Signed-off-by: Ian Munsie