Skip to content

Commit 4e80aa9

Browse files
committed
small fixes
1 parent 62f98c5 commit 4e80aa9

7 files changed

Lines changed: 61 additions & 20 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
- Fixed a memory leak when showing the confirmation dialog
77
- Fixed a memory leak when opening the settings menu
88
- Fixed a potential memory leak on app exit
9+
- Added a warning to the IR Dazzler menu option for the Poltergeist board from rabbit-labs
10+
- Miscellaneous memory optimisations
911

1012
## v1.6.2
1113

src/app_state.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ struct AppState {
7070
FuriMutex* buffer_mutex;
7171
// UART Context
7272
UartContext* uart_context;
73-
FilterConfig* filter_config;
73+
// FilterConfig is small enough to embed directly
74+
FilterConfig filter_config;
7475

7576
// Settings
7677
Settings settings;

src/main.c

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,8 @@ int32_t ghost_esp_app(void* p) {
7575
state->previous_view = 0;
7676
state->came_from_settings = false;
7777

78-
// Initialize essential text buffer (shared log/view buffer)
7978
state->textBoxBuffer = malloc(TEXT_LOG_BUFFER_SIZE);
80-
if(state->textBoxBuffer) {
79+
if(state && state->textBoxBuffer) {
8180
memset(state->textBoxBuffer, 0, TEXT_LOG_BUFFER_SIZE);
8281
}
8382
state->buffer_length = 0;
@@ -147,16 +146,13 @@ int32_t ghost_esp_app(void* p) {
147146
}
148147

149148
// Initialize filter config
150-
state->filter_config = malloc(sizeof(FilterConfig));
151-
if(state->filter_config) {
152-
state->filter_config->enabled = state->settings.enable_filtering_index;
153-
state->filter_config->show_ble_status = true;
154-
state->filter_config->show_wifi_status = true;
155-
state->filter_config->show_flipper_devices = true;
156-
state->filter_config->show_wifi_networks = true;
157-
state->filter_config->strip_ansi_codes = true;
158-
state->filter_config->add_prefixes = true;
159-
}
149+
state->filter_config.enabled = state->settings.enable_filtering_index;
150+
state->filter_config.show_ble_status = true;
151+
state->filter_config.show_wifi_status = true;
152+
state->filter_config.show_flipper_devices = true;
153+
state->filter_config.show_wifi_networks = true;
154+
state->filter_config.strip_ansi_codes = true;
155+
state->filter_config.add_prefixes = true;
160156

161157
// Set up settings UI context
162158
state->settings_ui_context.settings = &state->settings;
@@ -295,6 +291,7 @@ int32_t ghost_esp_app(void* p) {
295291
// Clean up UART context (this will also handle storage cleanup)
296292
if(state && state->uart_context) {
297293
FURI_LOG_I("Ghost_ESP", "Freeing UART context...");
294+
uart_cleanup_capture_streams(state->uart_context); // Ensure capture streams are freed
298295
uart_free(state->uart_context);
299296
state->uart_context = NULL;
300297
FURI_LOG_I("Ghost_ESP", "UART context freed.");
@@ -376,7 +373,7 @@ int32_t ghost_esp_app(void* p) {
376373
FURI_LOG_I("Ghost_ESP", "Freeing buffers...");
377374
if(state && state->input_buffer) free(state->input_buffer);
378375
if(state && state->textBoxBuffer) free(state->textBoxBuffer);
379-
if(state && state->filter_config) free(state->filter_config);
376+
// state->filter_config is now embedded, no need to free
380377
if(state && state->ir_file_buffer) free(state->ir_file_buffer);
381378
if(state && state->active_confirm_context) {
382379
FURI_LOG_I("Ghost_ESP", "Freeing active confirmation context...");

src/menu.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2144,7 +2144,7 @@ static bool handle_ir_command_feedback_ex(
21442144
char raw_buffer[512];
21452145
size_t len = 0;
21462146
char* message = state->confirmation_message;
2147-
char summary[96];
2147+
char summary[128];
21482148
message[0] = '\0';
21492149
summary[0] = '\0';
21502150
raw_buffer[0] = '\0';
@@ -2278,6 +2278,11 @@ static bool handle_ir_command_feedback_ex(
22782278
}
22792279

22802280
if(saw_ok && summary[0] && !message[0]) {
2281+
// Truncate summary if needed to prevent buffer overflow when combining
2282+
size_t max_len = sizeof(state->confirmation_message) - 10; // Reserve space for "Send OK\n"
2283+
if(strlen(summary) > max_len) {
2284+
summary[max_len] = '\0';
2285+
}
22812286
snprintf(
22822287
message,
22832288
sizeof(state->confirmation_message),
@@ -2303,6 +2308,11 @@ static bool handle_ir_command_feedback_ex(
23032308
strstr(line, "status OK") || strstr(line, "ir signal transmission complete")) {
23042309
saw_ok = true;
23052310
if(summary[0]) {
2311+
// Truncate summary if needed
2312+
size_t max_len = sizeof(state->confirmation_message) - 10;
2313+
if(strlen(summary) > max_len) {
2314+
summary[max_len] = '\0';
2315+
}
23062316
snprintf(
23072317
message,
23082318
sizeof(state->confirmation_message),
@@ -2615,6 +2625,10 @@ static void execute_menu_command(AppState* state, const MenuCommand* command) {
26152625
return;
26162626
}
26172627
if(strcmp(command->command, "send_ir_file") == 0) {
2628+
// Ensure capture streams are cleaned up before opening file browser
2629+
if(state->uart_context) {
2630+
uart_cleanup_capture_streams(state->uart_context);
2631+
}
26182632
send_ir_file(state);
26192633
return;
26202634
}
@@ -3395,9 +3409,10 @@ bool back_event_callback(void* context) {
33953409
}
33963410
FURI_LOG_D("Ghost ESP", "Handling text box view exit");
33973411

3398-
// Cleanup text buffer
3412+
// Cleanup text buffer and capture streams
33993413
if(state->uart_context) {
34003414
uart_reset_text_buffers(state->uart_context);
3415+
uart_cleanup_capture_streams(state->uart_context);
34013416
}
34023417
if(state->textBoxBuffer) {
34033418
state->buffer_length = 0;

src/settings_ui.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,7 @@ bool settings_set(Settings* settings, SettingKey key, uint8_t value, void* conte
211211
SettingsUIContext* settings_context = (SettingsUIContext*)context;
212212
if(settings_context->context) {
213213
AppState* app_state = (AppState*)settings_context->context;
214-
if(app_state->filter_config) {
215-
app_state->filter_config->enabled = value;
216-
}
214+
app_state->filter_config.enabled = value;
217215
}
218216
}
219217
changed = true;

src/uart_utils.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,33 @@ bool uart_is_esp_connected(UartContext* uart) {
738738
return connected;
739739
}
740740

741+
void uart_cleanup_capture_streams(UartContext* uart) {
742+
if(!uart) return;
743+
744+
if(uart->is_serial_active) {
745+
furi_hal_serial_async_rx_stop(uart->serial_handle);
746+
}
747+
748+
if(uart->pcap_stream) {
749+
furi_stream_buffer_free(uart->pcap_stream);
750+
uart->pcap_stream = NULL;
751+
FURI_LOG_I("UART", "Freed PCAP stream on exit");
752+
}
753+
if(uart->csv_stream) {
754+
furi_stream_buffer_free(uart->csv_stream);
755+
uart->csv_stream = NULL;
756+
FURI_LOG_I("UART", "Freed CSV stream on exit");
757+
}
758+
759+
uart->pcap = false;
760+
uart->csv = false;
761+
uart->pcap_flush_pending = false;
762+
763+
if(uart->is_serial_active) {
764+
furi_hal_serial_async_rx_start(uart->serial_handle, uart_rx_callback, uart, false);
765+
}
766+
}
767+
741768
bool uart_receive_data(
742769
UartContext* uart,
743770
ViewDispatcher* view_dispatcher,

src/uart_utils.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
#define BAUDRATE (115200)
2525

26-
#define TEXT_BOX_STORE_SIZE (12 * 1024) // 12KB text box buffer size
26+
#define TEXT_BOX_STORE_SIZE (8 * 1024) // 8KB text box buffer size
2727
#define RX_BUF_SIZE 2048
2828
#define PCAP_BUF_SIZE 4096
2929
#define GHOST_ESP_APP_FOLDER "/ext/apps_data/ghost_esp"
@@ -113,6 +113,7 @@ void uart_storage_safe_cleanup(UartStorageContext* ctx);
113113
void uart_reset_text_buffers(UartContext* uart);
114114
bool uart_copy_text_buffer(UartContext* uart, char* out, size_t out_size, size_t* out_len);
115115
bool uart_copy_text_buffer_tail(UartContext* uart, char* out, size_t out_size, size_t* out_len);
116+
void uart_cleanup_capture_streams(UartContext* uart);
116117

117118
#endif
118119

0 commit comments

Comments
 (0)