Commit fe8f7cb
committed
cheevos: NULL-check retry-achievement info malloc + release task on OOM
rcheevos_award_achievement's 'badge not ready yet, retry later' path
allocated a task + a retry-info struct with no guard:
task = task_init();
if (!task)
rcheevos_show_achievement_popup(cheevo, rarity);
else
{
struct rcheevos_retry_achievement_info_t* info;
info = (struct rcheevos_retry_achievement_info_t*)malloc(sizeof(*info));
info->achievement_id = cheevo->id; /* NULL-deref on OOM */
info->rarity = rarity;
...
task->user_data = info;
task_queue_push(task);
}
Two ways this breaks on OOM:
1. Immediate segfault: info->achievement_id is dereferenced on the
very next line after malloc.
2. Dormant segfault via the task handler: if something somehow
survived the immediate dereference (it won't - but as a
reasoning exercise) and we pushed a task with user_data=NULL,
rcheevos_retry_achievement_popup (line 347) would do
'info->achievement_id' when the task fires.
Also leaks the just-allocated retro_task_t on the info-malloc
failure path, since task_queue_push never runs to take ownership.
Fix: NULL-check info. On OOM, free the task (task_init is a plain
malloc, free is the correct release for an un-pushed task) and
fall back to rcheevos_show_achievement_popup immediately - the
same behaviour as the existing '!task' branch. That's the
graceful-degradation path: the popup just shows the placeholder
badge instead of waiting for the real one.
Thread-safety: unchanged. rcheevos_award_achievement runs on the
main thread from the rcheevos callback; info is owned by the task
until the handler releases it.1 parent 71eeacf commit fe8f7cb
1 file changed
Lines changed: 23 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
406 | 406 | | |
407 | 407 | | |
408 | 408 | | |
409 | | - | |
410 | | - | |
411 | | - | |
412 | | - | |
413 | | - | |
414 | | - | |
415 | | - | |
416 | | - | |
417 | | - | |
418 | | - | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
419 | 432 | | |
420 | 433 | | |
421 | 434 | | |
| |||
0 commit comments