10 years, 5 months ago.

You have a memory leak

this is in reference to this library: https://mbed.org/users/dglover77/code/HCSR04/

You may want to fix this...

In your ctor, you allocate memory:

_echo_int = new InterruptIn( echo );

You do not specify a dtor so the default dtor will be used. However, the default dtor will not deallocate the memory you allocated in the ctor. You can fix this by either: 1) creating a dtor that will deallocate the memory OR 2) declare _echo_int as an InterruptIn instead of an InterrupIn *

In the latter case, the ctor will allocate memory on the stack (instead of the heap) then deallocation will occur when the instance is destroyed.

Question relating to:

It is generally more effective to either send the maker a personal message, or fork it with the fix, and then it can't hurt to send him a pull request.

But especially since it is 1.5 years old I doubt he will notice this question (which isn't really a question).

posted by Erik - 24 Nov 2013

Judging by the comments it looks like trigger_out used to be allocated the same way and has already been fixed, so it shouldn't be hard to rewrite it.

posted by Oliver Broad 26 Apr 2016
Be the first to answer this question.