Hi, what's the problem?
Heart uses LPHEART typedef which is a pointer to a structure. Let's take a look at the heart_new function:
As you can see, this function calls calloc to allocate memory for LPHEART,
but this operation causes a little issue - calloc is never released!
- Wait... we have function to free memory (heart_delete)
- Yes, never used anywhere...
My potential solution
Instead of calling heart_delete, I use a smart pointer to store LPHEART
which will be automatically freed.
libthecore -> heart.h:
// We need to move the raw pointer to shared:
typedef struct std::shared_ptr<HEART> LPHEART;
libthecore -> heart.cpp:
// From heart_new function remove this variable:
LPHEART ht;
// Then edit:
CREATE(ht, HEART, 1);
// In this way:
auto ht = std::make_shared<HEART>();
Of course you can remove the heart_delete function from both files now. That's all!