Commit 741ead4
committed
menu/xmb, menu/ozone: fix leak + null-deref + needless strdup in update_savestate_thumbnail_path
Both xmb and ozone have an identical three-bug stack in their
update_savestate_thumbnail_path implementations, matching the pattern
already fixed for materialui in commit 93449d3:
1. Null-deref: xmb->savestate_thumbnail_file_path (xmb) /
ozone->savestate_thumbnail_file_path (ozone) is dereferenced by
strdup BEFORE the 'if (!xmb) return;' / 'if (!ozone) return;'
guard further down. If data was ever NULL, the guard would
never be reached.
2. Leak: the strdup result is assigned to a const char *
(current_path) and never freed on any exit path - not when
savestate_thumbnail is disabled, not when the entry label check
fails, not on the success path either. Called on every selection
change in the state-slot menu, so the leak is quickly user-visible
with typical navigation.
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, sidesteps both the leak and the OOM failure mode
(where strdup returning NULL silently made string_is_equal
compare against NULL - undefined behaviour).
Fix both: declare 'char 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; xmb_handle_t / ozone_handle_t state is not shared across
threads. The only writes touch the driver-specific savestate
thumbnail path and thumbnails.savestate state, both already single-
thread owned.
With this commit the three menu drivers that implement savestate
thumbnails (materialui, xmb, ozone) all use the same corrected
pattern.1 parent e976983 commit 741ead4
2 files changed
Lines changed: 27 additions & 6 deletions
File tree
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3892 | 3892 | | |
3893 | 3893 | | |
3894 | 3894 | | |
3895 | | - | |
3896 | | - | |
| 3895 | + | |
| 3896 | + | |
| 3897 | + | |
| 3898 | + | |
| 3899 | + | |
| 3900 | + | |
| 3901 | + | |
| 3902 | + | |
3897 | 3903 | | |
3898 | 3904 | | |
3899 | 3905 | | |
3900 | 3906 | | |
| 3907 | + | |
| 3908 | + | |
| 3909 | + | |
3901 | 3910 | | |
3902 | 3911 | | |
3903 | 3912 | | |
| |||
3950 | 3959 | | |
3951 | 3960 | | |
3952 | 3961 | | |
3953 | | - | |
| 3962 | + | |
3954 | 3963 | | |
3955 | 3964 | | |
3956 | 3965 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1305 | 1305 | | |
1306 | 1306 | | |
1307 | 1307 | | |
1308 | | - | |
1309 | | - | |
| 1308 | + | |
| 1309 | + | |
| 1310 | + | |
| 1311 | + | |
| 1312 | + | |
| 1313 | + | |
| 1314 | + | |
| 1315 | + | |
| 1316 | + | |
| 1317 | + | |
| 1318 | + | |
1310 | 1319 | | |
1311 | 1320 | | |
1312 | 1321 | | |
1313 | 1322 | | |
| 1323 | + | |
| 1324 | + | |
| 1325 | + | |
1314 | 1326 | | |
1315 | 1327 | | |
1316 | 1328 | | |
| |||
1356 | 1368 | | |
1357 | 1369 | | |
1358 | 1370 | | |
1359 | | - | |
| 1371 | + | |
1360 | 1372 | | |
1361 | 1373 | | |
1362 | 1374 | | |
| |||
0 commit comments