Commit 3785495
committed
scattered OOM fixes: core_backup entries leak, netplay core_netpacket_interface and rooms_data
Three small unrelated OOM bugs found during a top-level sweep.
=== core_backup.c: core_backup_list_init entries leak on OOM ===
if (!(entries = calloc(dir_list->size, sizeof(*entries))))
{
string_list_free(dir_list);
return NULL;
}
if (!(backup_list = malloc(sizeof(*backup_list))))
{
string_list_free(dir_list);
return NULL; /* entries leaks here */
}
The backup_list malloc failure path freed dir_list but not
entries. On OOM the entries buffer (potentially large -
dir_list->size * sizeof(core_backup_list_entry_t)) was leaked.
Fix: free(entries) in the failure block.
=== network/netplay/netplay_frontend.c: core_netpacket_interface malloc ===
net_st->core_netpacket_interface = malloc(
sizeof(*net_st->core_netpacket_interface));
*net_st->core_netpacket_interface = *(struct retro_netpacket_callback*)data;
malloc unchecked; the struct-copy on the next line NULL-derefs
on OOM. Triggered by RARCH_NETPLAY_CTL_SET_CORE_PACKET_INTERFACE,
which a core calls via RETRO_ENVIRONMENT_SET_NETPACKET_INTERFACE.
Fix: NULL-check, break out of the env-dispatch case on failure.
The companion RARCH_NETPLAY_CTL_USE_CORE_PACKET_INTERFACE case
(lines ~9782) correctly reports unavailability when the pointer
is NULL ('ret = (net_st->core_netpacket_interface != NULL)'),
so skipping the copy + path-redirect gracefully signals 'no
core netpacket interface available' - strictly better than a
segfault in the middle of core init.
=== network/netplay/netplay_room_parse.c: rooms_data calloc ===
net_st->rooms_data = (struct netplay_rooms*)
calloc(1, sizeof(*net_st->rooms_data));
rjson_parse_quick(buf, len, &ctx, 0, ...)
calloc unchecked. The rjson_parse_quick member/object-start
handlers dereference net_st->rooms_data freely (line ~103
'if (!net_st->rooms_data->head)'), so OOM causes a NULL-deref
partway through JSON parsing.
Fix: NULL-check before invoking the parser and return 0 (the
existing success return). Callers are two menu/Discord lobby
refresh paths that gate subsequent iteration on
netplay_rooms_get_count() - that function already NULL-checks
rooms_data at line 350 and returns 0, causing the 'no rooms
available' UI state. Matches the 'empty JSON response' success
outcome.
NOTE: the inner per-room callocs inside the parse callbacks
(lines ~105 and ~110) are still unchecked. Fixing those
properly would need threading an error flag through the entire
parse-context struct since rjson callbacks can't propagate OOM
out of the parser. Out of scope for this patch; this commit
plugs only the outer container alloc which is the entry point
for every call.
=== Thread-safety ===
All three sites run on the main thread (menu interaction,
core env dispatch, lobby refresh). No lock discipline changes.
=== Reachability ===
* core_backup_list_init: every core-backup menu open, every
core-updater restore scan. dir_list->size scales with the
number of backups present so the leaked buffer can be
substantial on long-running installations.
* core_netpacket_interface: every core that supports netplay
via the core-packet-interface API (modern netplay-aware
cores).
* rooms_data: every netplay lobby refresh - both the menu's
explicit 'refresh room list' action and Discord integration
auto-refreshes.1 parent 3a5775d commit 3785495
3 files changed
Lines changed: 27 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
592 | 592 | | |
593 | 593 | | |
594 | 594 | | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
595 | 598 | | |
596 | 599 | | |
597 | 600 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9770 | 9770 | | |
9771 | 9771 | | |
9772 | 9772 | | |
| 9773 | + | |
| 9774 | + | |
| 9775 | + | |
| 9776 | + | |
| 9777 | + | |
| 9778 | + | |
| 9779 | + | |
9773 | 9780 | | |
9774 | 9781 | | |
9775 | 9782 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
288 | 288 | | |
289 | 289 | | |
290 | 290 | | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
291 | 308 | | |
292 | 309 | | |
293 | 310 | | |
| |||
0 commit comments