Commit 494196f
committed
menu/drivers: fix leaks, OOM NULL-derefs and dead-code guards across xmb, ozone, materialui
Five bugs across the xmb, ozone, and materialui menu drivers,
surfaced during an alloc-site sweep of menu/drivers/.
=== menu/drivers/xmb.c: xmb_messagebox leak ===
static void xmb_messagebox(void *data, const char *message)
{
xmb_handle_t *xmb = (xmb_handle_t*)data;
if (xmb && message && *message)
xmb->box_message = strdup(message);
}
Overwrote any previously-set xmb->box_message without freeing
it. The render path at line ~9215 consumes box_message once
(strlcpy to stack msg, then free + NULL), but nothing prevents
xmb_messagebox from being called twice between renders (rapid
error notifications, background task completion triggering a
second box before the menu repaints). Pre-patch every
additional call leaked the previous message.
Fix: free the old box_message before strdup'ing the new one,
mirroring ozone's equivalent pending_message handling.
=== menu/drivers/xmb.c: xmb_init_ribbon OOM NULL-deref ===
xmb_init_ribbon allocated two scratch arrays and immediately
wrote into them in a tight loop:
float *dummy = (float*)calloc(4 * vertices_total, sizeof(float));
float *ribbon_verts = (float*)calloc(2 * vertices_total, sizeof(float));
for (r = 0; r < XMB_RIBBON_ROWS - 1; r++)
{
for (c = 0; c < XMB_RIBBON_COLS; c++)
{
...
xmb_ribbon_set_vertex(ribbon_verts, i, r, col);
...
}
}
coords.color = dummy;
coords.vertex = ribbon_verts;
coords.tex_coord = dummy;
coords.lut_tex_coord = dummy;
...
video_coord_array_append(ca, &coords, coords.vertices);
Both callocs were unchecked. xmb_ribbon_set_vertex does
'ribbon_verts[idx++] = ...' unconditionally, and
video_coord_array_append reads through coords.color /
tex_coord / lut_tex_coord (= dummy) for every vertex -
NULL-derefs on OOM.
Fix: NULL-check both callocs and skip ribbon init entirely on
OOM. The ribbon is a decorative background animation;
degraded visuals are strictly better than a crash. Existing
free()s at the bottom are NULL-safe.
=== menu/drivers/xmb.c: .lvw console_name leak ===
In xmb_context_reset_horizontal_list, the .lpl branch
correctly frees the old console_name before strdup'ing the
new one:
if (node->console_name)
free(node->console_name);
if (console_name)
node->console_name = strdup(console_name);
else
node->console_name = strdup(path);
but the .lvw (Explore View) branch just overwrote:
node->console_name = strdup(path + strlen(...) + 2);
xmb_context_reset_horizontal_list is called on every theme
change / refresh, so without the free the .lvw console_name
from the previous reset leaked.
Fix: match the .lpl pattern - free old before strdup.
=== menu/drivers/ozone.c: .lvw console_name leak ===
Twin of the xmb bug above - ozone_context_reset_horizontal_
list had the same missing-free in its .lvw branch, while the
.lpl branch frees correctly. Same fix.
=== menu/drivers/materialui.c: dead-code !node guard ===
materialui_list_insert had a classic dead-code NULL-guard:
node = (materialui_node_t*)list->list[i].userdata;
if (!node)
{
node = (materialui_node_t*)malloc(sizeof(materialui_node_t));
node->icon_type = MUI_ICON_TYPE_NONE;
node->icon_texture_index = 0;
... /* 24 lines of unconditional node-> writes */
}
else
{
gfx_thumbnail_reset(&node->thumbnails.primary);
gfx_thumbnail_reset(&node->thumbnails.secondary);
thumbnail_reset = true;
}
if (!node)
return;
node->icon_type = MUI_ICON_TYPE_NONE;
...
The 'if (!node) return' at the bottom of that block only
fires after the preceding 24 lines have already unconditionally
dereferenced node. On OOM the field writes NULL-deref long
before the guard can run - same class of bug as the iohid
hoist fixed in 9e840aa.
Fix: hoist the NULL-check to immediately after the malloc,
and store NULL into list->list[i].userdata so the list entry
has the same 'no node' state it would have had if userdata
had been NULL from the start. Downstream materialui renders
NULL-userdata entries as bare items without the materialui-
specific metadata (icons, thumbnails) - degraded but
functional.
The downstream dead-code 'if (!node) return' at line ~11308
is now truly unreachable from all three prior paths (if-branch
succeeds and returns early on OOM, if-branch fills node; else-
branch uses non-NULL existing node). Left in place as defensive
scaffolding rather than churning the diff further.
=== Swept-clean in the same pass ===
Verified NULL-checked / leak-free in the same files:
- xmb.c: xmb_alloc_node malloc (guarded), box_message / bg_
file_path other sites (free-before-strdup), init callocs
for menu_handle_t and xmb_handle_t (guarded), tab-switch
menu_stack label strdups (free-before-strdup), xmb_menu_
init_list (goto error cleanup).
- ozone.c: ozone_copy_node malloc (guarded with prior audit
comment), ozone_list_deep_copy strdup/malloc patterns
(guarded with prior audit comment), pending_message strdup
(free-before-strdup), init callocs, ozone_alloc_node malloc
(guarded).
- materialui.c: playlist.icons malloc (guarded), tab-switch
label strdups (free-before-strdup), init
callocs (guarded), playlist_file / image_file strdups
(downstream NULL-guarded).
- rgui.c: all 9 alloc sites guarded. rgui_set_aspect_ratio
has the right shape: pre-alloc free at entry, per-step
NULL-checks on each buffer alloc, caller cleanup via goto
error. The 'leak on mid-function failure'
impression was wrong - the next entry (or init failure
cleanup) frees whatever partial state survived.
Thread-safety: all menu driver paths run on the main menu
thread; no concurrency concerns.
Reachability:
- xmb_messagebox leak: every rapid double-message (cheevo
unlock + task completion, rapid config errors, etc.)
- xmb_init_ribbon OOM: one-shot at xmb menu driver init.
- xmb / ozone .lvw leak: every theme change / refresh while
at least one Explore View entry is in the horizontal list.
Explore View is opt-in but common.
- materialui dead-code guard: every menu list insertion
against a fresh slot would crash on OOM pre-patch.
materialui_list_insert fires on every menu push - the
main menu alone inserts ~20 entries on boot.
Scope: local to each file; no API changes, no header changes.1 parent 552cf85 commit 494196f
3 files changed
Lines changed: 60 additions & 0 deletions
File tree
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11252 | 11252 | | |
11253 | 11253 | | |
11254 | 11254 | | |
| 11255 | + | |
| 11256 | + | |
| 11257 | + | |
| 11258 | + | |
| 11259 | + | |
| 11260 | + | |
| 11261 | + | |
| 11262 | + | |
| 11263 | + | |
| 11264 | + | |
| 11265 | + | |
| 11266 | + | |
| 11267 | + | |
| 11268 | + | |
| 11269 | + | |
| 11270 | + | |
| 11271 | + | |
| 11272 | + | |
11255 | 11273 | | |
11256 | 11274 | | |
11257 | 11275 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5235 | 5235 | | |
5236 | 5236 | | |
5237 | 5237 | | |
| 5238 | + | |
| 5239 | + | |
| 5240 | + | |
| 5241 | + | |
| 5242 | + | |
| 5243 | + | |
| 5244 | + | |
5238 | 5245 | | |
5239 | 5246 | | |
5240 | 5247 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1094 | 1094 | | |
1095 | 1095 | | |
1096 | 1096 | | |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
1097 | 1108 | | |
| 1109 | + | |
1098 | 1110 | | |
1099 | 1111 | | |
1100 | 1112 | | |
| |||
3085 | 3097 | | |
3086 | 3098 | | |
3087 | 3099 | | |
| 3100 | + | |
| 3101 | + | |
| 3102 | + | |
| 3103 | + | |
| 3104 | + | |
| 3105 | + | |
| 3106 | + | |
3088 | 3107 | | |
3089 | 3108 | | |
3090 | 3109 | | |
| |||
9284 | 9303 | | |
9285 | 9304 | | |
9286 | 9305 | | |
| 9306 | + | |
| 9307 | + | |
| 9308 | + | |
| 9309 | + | |
| 9310 | + | |
| 9311 | + | |
| 9312 | + | |
| 9313 | + | |
| 9314 | + | |
| 9315 | + | |
| 9316 | + | |
| 9317 | + | |
| 9318 | + | |
| 9319 | + | |
| 9320 | + | |
| 9321 | + | |
9287 | 9322 | | |
9288 | 9323 | | |
9289 | 9324 | | |
| |||
0 commit comments