-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Description
median() calls _orderedValues() in order to get a pointer to a newly allocated sorted copy of the sample buffer. When it returns, it looses that pointer and never frees the memory.
This creates a huge memory leak. I did an experiment with an Arduino Uno and a filter of size 5. Repeatedly calling median() makes the heap grow by 64 bytes per call, eventually crashing the Arduino.
The following seems to seal the leak:
diff --git a/Filter.cpp b/Filter.cpp
index 73b85a6..c18e049 100755
--- a/Filter.cpp
+++ b/Filter.cpp
@@ -167,6 +167,8 @@ long Filter::median() const {
median = ((medianValues->peek(midpoint) + medianValues->peek(midpoint+1)) * 10) / 2;
median = _longRound(median, 10);
}
+ medianValues->flush();
+ free(medianValues);
return(median);
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels