Skip to content

Commit 1804100

Browse files
authored
fix(timer): Fix memory leak in espp::HighResolutionTimer when calling start repeatedly (#226)
1 parent 4351fef commit 1804100

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

components/timer/include/high_resolution_timer.hpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,7 @@ class HighResolutionTimer : public espp::BaseComponent {
4949
}
5050

5151
/// Destructor
52-
~HighResolutionTimer() {
53-
stop();
54-
if (timer_handle_) {
55-
esp_timer_delete(timer_handle_);
56-
}
57-
}
52+
~HighResolutionTimer() { stop(); }
5853

5954
/// Start the timer
6055
/// @param period_us Period of the timer in microseconds, or timeout if
@@ -111,6 +106,10 @@ class HighResolutionTimer : public espp::BaseComponent {
111106
if (is_running()) {
112107
esp_timer_stop(timer_handle_);
113108
}
109+
if (timer_handle_) {
110+
esp_timer_delete(timer_handle_);
111+
timer_handle_ = nullptr;
112+
}
114113
}
115114

116115
/// Check if the timer is running

0 commit comments

Comments
 (0)