Commit 93449d3
committed
menu/materialui: fix leak + null-deref + needless strdup in update_savestate_thumbnail_path
The function had three problems stacked in a handful of lines:
1. Null-deref: mui->savestate_thumbnail_file_path was dereferenced
(via strdup) BEFORE the 'if (!mui) return;' guard. If data was
ever NULL, the guard would never be reached.
2. Leak: the strdup result was assigned to a const char * and never
freed on any exit path - not when savestate_thumbnail was
disabled, not when the entry label check failed, not on the
success path either. Called frequently (on every selection
change in the savestate list) so the leak was quickly user-
visible.
3. Needless strdup: savestate_thumbnail_file_path is a fixed-size
char[PATH_MAX_LENGTH] embedded in the struct, not a pointer.
Heap allocation is unnecessary; a stack buffer of the same size
does the job and sidesteps both the leak and the OOM failure
mode (where strdup returning NULL silently flipped the
string_is_equal comparison below).
Fix: declare a local 'old_path[PATH_MAX_LENGTH]' AFTER the NULL
guard, strlcpy the current path into it before the field is
cleared, and compare against it further down. No heap allocation,
no leak, no dereference before NULL check.
Thread-safety: unchanged. Menu driver callbacks run on the main
thread; materialui_handle_t state is not shared across threads.
The only writes touch mui->savestate_thumbnail_file_path and
mui->thumbnails.savestate, both already single-thread owned.1 parent 91eba66 commit 93449d3
1 file changed
Lines changed: 13 additions & 3 deletions
File tree
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2484 | 2484 | | |
2485 | 2485 | | |
2486 | 2486 | | |
2487 | | - | |
2488 | | - | |
| 2487 | + | |
| 2488 | + | |
2489 | 2489 | | |
2490 | 2490 | | |
2491 | 2491 | | |
2492 | 2492 | | |
| 2493 | + | |
| 2494 | + | |
| 2495 | + | |
| 2496 | + | |
| 2497 | + | |
| 2498 | + | |
| 2499 | + | |
| 2500 | + | |
| 2501 | + | |
| 2502 | + | |
2493 | 2503 | | |
2494 | 2504 | | |
2495 | 2505 | | |
| |||
2525 | 2535 | | |
2526 | 2536 | | |
2527 | 2537 | | |
2528 | | - | |
| 2538 | + | |
2529 | 2539 | | |
2530 | 2540 | | |
2531 | 2541 | | |
| |||
0 commit comments