Commit c99f8a5
committed
runahead: defensive ordering and OOM hardening in mylist
allocator
Three small defensive changes in runahead's helper allocators -
no behavioral change on the happy path.
runahead_secondary_core_destroy: filestream_delete was called
on runloop_st->secondary_library_path before the NULL check
that follows. filestream_delete is currently NULL-safe via
retro_vfs_file_remove_impl's path guard, but the explicit
NULL check after the use is misleading. Reorder so a single
NULL check guards both the delete and the free, and document
that the explicit guard also protects against future VFS-layer
changes.
mylist_resize: the realloc on growth had no NULL check, and
the immediately-following loop wrote NULL to list->data[i] -
NULL-deref on OOM. Stash the realloc result in a local, return
early on NULL, and only assign to list->data on success. The
caller chain tolerates incomplete growth: runahead's input
list element constructor is already NULL-safe (see the comment
at input_list_element_constructor:721-727), and
runahead_input_state_set_last has an 'if (element)' guard.
mylist_add_element: read list->size before the 'if (list)'
NULL check - the check was either dead or in the wrong place.
Reorder to NULL-check first, then handle the new case where
mylist_resize fails to grow (list->size still equals old_size,
so list->data[old_size] is out of bounds).
mylist_create: malloc and calloc had no NULL checks. malloc
NULL-deref'd on the field-write block; calloc NULL-deref'd
on first use. malloc failure now sets *list_p to NULL and
returns; calloc failure leaves list->data NULL with capacity
0, which mylist_resize's realloc-from-NULL path handles
correctly (realloc(NULL, n) is well-defined as malloc(n)).
The runahead lists are tiny (frame buffers, ~16 entries), so
OOM here is unlikely in practice. But the file already has
NULL-hardening comments at input_list_element_constructor
and input_list_element_realloc, so adding the missing checks
fits the established direction.1 parent 4666d70 commit c99f8a5
1 file changed
Lines changed: 41 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
201 | 201 | | |
202 | 202 | | |
203 | 203 | | |
204 | | - | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
205 | 209 | | |
| 210 | + | |
| 211 | + | |
206 | 212 | | |
207 | | - | |
| 213 | + | |
| 214 | + | |
208 | 215 | | |
209 | 216 | | |
210 | 217 | | |
| |||
629 | 636 | | |
630 | 637 | | |
631 | 638 | | |
| 639 | + | |
| 640 | + | |
632 | 641 | | |
633 | 642 | | |
634 | 643 | | |
635 | | - | |
636 | | - | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
637 | 652 | | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
638 | 656 | | |
639 | 657 | | |
640 | 658 | | |
| |||
670 | 688 | | |
671 | 689 | | |
672 | 690 | | |
673 | | - | |
674 | | - | |
675 | | - | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
676 | 701 | | |
677 | 702 | | |
678 | 703 | | |
| |||
706 | 731 | | |
707 | 732 | | |
708 | 733 | | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
709 | 739 | | |
710 | 740 | | |
711 | 741 | | |
712 | 742 | | |
713 | 743 | | |
714 | | - | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
715 | 748 | | |
716 | 749 | | |
717 | 750 | | |
| |||
0 commit comments