alandefreitas / pareto

Spatial Containers, Pareto Fronts, and Pareto Archives
https://alandefreitas.github.io/pareto/
MIT License
92 stars 9 forks source link

Memory Leak #6

Open jkuck opened 2 years ago

jkuck commented 2 years ago

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 commented 2 years ago

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

alandefreitas commented 2 years ago

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.

jkuck commented 2 years ago

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