]> git.earman.xyz Git - sensor-watch.git/commitdiff
fix memory leak when waking from screensaver mode
authorJoey Castillo <jose.castillo@gmail.com>
Tue, 5 Oct 2021 19:55:34 +0000 (15:55 -0400)
committerJoey Castillo <jose.castillo@gmail.com>
Tue, 5 Oct 2021 19:55:34 +0000 (15:55 -0400)
launcher/launcher.c
launcher/widgets/clock/simple_clock_widget.c
launcher/widgets/settings/preferences_widget.c
launcher/widgets/settings/set_time_widget.c

index 160b8d2a4ec9d32abf3d26d634f86a30c314c9bf..7d87c58a1d92dbb0e12826fb16daa6002c1752cb 100644 (file)
@@ -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();
index 83b5a7138a38d6447bdf296c82daf87e2ba77fec..0c89cbc265e9cccade689f7e009b97d2cb33f6f6 100644 (file)
@@ -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) {
index 79508ab3cda119a8678d844b54a094da7ac53f27..40e0ac508a710306513274327bb8838c9b67d24f 100644 (file)
@@ -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) {
index c65459abdc5c1071a028ac4737cb93eddea8baa0..c7949a4f0ab08f46a030c7bcac64ce62a0be4735 100644 (file)
@@ -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) {