summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoey Castillo <jose.castillo@gmail.com>2021-10-05 15:55:34 -0400
committerJoey Castillo <jose.castillo@gmail.com>2021-10-05 15:55:34 -0400
commit8372e37bea5313a131054081e84fe7e9a45f32a9 (patch)
tree1d23f095e2ecbdd3d6d6af08053f3f6b06e15c97
parent83192b3a580c19eb694ca7951650db87eeb582ad (diff)
downloadSensor-Watch-8372e37bea5313a131054081e84fe7e9a45f32a9.tar.gz
Sensor-Watch-8372e37bea5313a131054081e84fe7e9a45f32a9.tar.bz2
Sensor-Watch-8372e37bea5313a131054081e84fe7e9a45f32a9.zip
fix memory leak when waking from screensaver mode
-rw-r--r--launcher/launcher.c8
-rw-r--r--launcher/widgets/clock/simple_clock_widget.c2
-rw-r--r--launcher/widgets/settings/preferences_widget.c2
-rw-r--r--launcher/widgets/settings/set_time_widget.c2
4 files changed, 11 insertions, 3 deletions
diff --git a/launcher/launcher.c b/launcher/launcher.c
index 160b8d2a..7d87c58a 100644
--- a/launcher/launcher.c
+++ b/launcher/launcher.c
@@ -56,6 +56,14 @@ void app_wake_from_deep_sleep() {
}
void app_setup() {
+ static bool is_first_launch = true;
+
+ if (is_first_launch) {
+ for(uint8_t i = 0; i < LAUNCHER_NUM_WIDGETS; i++) {
+ widget_contexts[i] = NULL;
+ is_first_launch = false;
+ }
+ }
if (launcher_state.screensaver_ticks != -1) {
watch_disable_extwake_interrupt(BTN_ALARM);
watch_rtc_disable_alarm_callback();
diff --git a/launcher/widgets/clock/simple_clock_widget.c b/launcher/widgets/clock/simple_clock_widget.c
index 83b5a713..0c89cbc2 100644
--- a/launcher/widgets/clock/simple_clock_widget.c
+++ b/launcher/widgets/clock/simple_clock_widget.c
@@ -5,7 +5,7 @@
void simple_clock_widget_setup(LauncherSettings *settings, void ** context_ptr) {
(void) settings;
// the only context we need is the timestamp of the previous tick.
- *context_ptr = malloc(sizeof(uint32_t));
+ if (*context_ptr == NULL) *context_ptr = malloc(sizeof(uint32_t));
}
void simple_clock_widget_activate(LauncherSettings *settings, void *context) {
diff --git a/launcher/widgets/settings/preferences_widget.c b/launcher/widgets/settings/preferences_widget.c
index 79508ab3..40e0ac50 100644
--- a/launcher/widgets/settings/preferences_widget.c
+++ b/launcher/widgets/settings/preferences_widget.c
@@ -7,7 +7,7 @@ const char preferences_widget_titles[PREFERENCES_WIDGET_NUM_PREFEFENCES][11] = {
void preferences_widget_setup(LauncherSettings *settings, void ** context_ptr) {
(void) settings;
- *context_ptr = malloc(sizeof(uint8_t));
+ if (*context_ptr == NULL) *context_ptr = malloc(sizeof(uint8_t));
}
void preferences_widget_activate(LauncherSettings *settings, void *context) {
diff --git a/launcher/widgets/settings/set_time_widget.c b/launcher/widgets/settings/set_time_widget.c
index c65459ab..c7949a4f 100644
--- a/launcher/widgets/settings/set_time_widget.c
+++ b/launcher/widgets/settings/set_time_widget.c
@@ -7,7 +7,7 @@ const char set_time_widget_titles[SET_TIME_WIDGET_NUM_SETTINGS][3] = {"HR", "MN"
void set_time_widget_setup(LauncherSettings *settings, void ** context_ptr) {
(void) settings;
- *context_ptr = malloc(sizeof(uint8_t));
+ if (*context_ptr == NULL) *context_ptr = malloc(sizeof(uint8_t));
}
void set_time_widget_activate(LauncherSettings *settings, void *context) {