pareto icon indicating copy to clipboard operation
pareto copied to clipboard

Memory Leak

Open jkuck opened this issue 2 years ago • 3 comments

Hi Alan, I'm making a call to pareto::front.hypervolume() and found that this call leaks memory. When running through valgrind, this is the error that I'm getting:

==77189== Mismatched free() / delete / delete []
==77189==    at 0x4C32D3B: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==77189==    by 0x1A6082: pareto::fpli_hv(double*, int, int, double const*) (hypervolume.h:820)
==77189==    by 0x1ACCDA: pareto::front<long, 3ul, unsigned int, pareto::r_tree<long, 3ul, unsigned int, std::less<long>, std::allocator<std::pair<pareto::point<long, 3ul, void> const, unsigned int> > > >::hypervolume(pareto::point<long, 3ul, void>) const (front.h:930)

And the final valgrind ouput looks like this:

==77189== 
==77189== HEAP SUMMARY:
==77189==     in use at exit: 391,049 bytes in 4,115 blocks
==77189==   total heap usage: 1,901,304 allocs, 1,897,189 frees, 471,587,726 bytes allocated
==77189== 
==77189== LEAK SUMMARY:
==77189==    definitely lost: 8,008 bytes in 32 blocks
==77189==    indirectly lost: 265,176 bytes in 2,133 blocks
==77189==      possibly lost: 0 bytes in 0 blocks
==77189==    still reachable: 117,865 bytes in 1,950 blocks
==77189==         suppressed: 0 bytes in 0 blocks
==77189== Rerun with --leak-check=full to see details of leaked memory
==77189== 
==77189== For counts of detected and suppressed errors, rerun with: -v
==77189== ERROR SUMMARY: 32487 errors from 7 contexts (suppressed: 0 from 0)

Do you have any ideas for fixing this problem? Thanks!

jkuck avatar Jun 02 '22 17:06 jkuck

I've submitted a pull request to fix this problem here: https://github.com/alandefreitas/pareto/pull/7

jkuck avatar Jun 03 '22 15:06 jkuck

Oh! I missed that free() when refactoring the code.

Since I'm pretty sure the original algorithm in http://lopez-ibanez.eu/hypervolume in not actively maintained, I should probably just refactor the whole thing to real C++ at some point.

alandefreitas avatar Jun 03 '22 23:06 alandefreitas

No worries, I really appreciate all the functionality that you've built :)

jkuck avatar Jun 04 '22 13:06 jkuck