Fix memory leak in lis2dw_monitor_face settings array
state->settings was malloc'd in lis2dw_monitor_face_setup() outside the guard that only runs on first allocation of the face's context. setup() is called again every time the watch wakes from deep sleep (movement.c's app_setup() re-runs watch_faces[i].setup() for every face on wake), so each wake cycle allocated a new settings array and abandoned the previous pointer with no matching free. Since NUM_SETTINGS is a compile-time constant, make settings a fixed-size array embedded directly in lis2dw_monitor_state_t instead of a separately malloc'd pointer, so it's allocated exactly once along with the rest of the state and never leaks.
This commit is contained in:
@@ -56,13 +56,16 @@ typedef struct {
|
||||
void (*advance)(void *);
|
||||
} lis2dw_settings_t;
|
||||
|
||||
/* Number of settings pages */
|
||||
#define NUM_SETTINGS 7
|
||||
|
||||
typedef struct {
|
||||
uint8_t axis:2; /* Axis to display */
|
||||
lis2dw_reading_t reading; /* Current reading */
|
||||
lis2dw_monitor_page_t page; /* Displayed page */
|
||||
lis2dw_device_state_t ds; /* Device state */
|
||||
uint8_t settings_page:3; /* Subpage in settings */
|
||||
lis2dw_settings_t *settings; /* Settings config */
|
||||
lis2dw_settings_t settings[NUM_SETTINGS]; /* Settings config */
|
||||
uint8_t show_title:6; /* Display face title */
|
||||
} lis2dw_monitor_state_t;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user