Commit b91adb8
Use Ruby's
`IO_Event_Selector_ready_push` (selector.c) and `IO_Event_Array_lookup` (array.h) both allocated internal bookkeeping structs via raw `malloc` paired with a debug-build-only `assert(...)`. In a release build (`NDEBUG`) the `assert` compiles to nothing, so if `malloc` returned `NULL` under memory pressure the next line dereferenced a null pointer and crashed the process.
Switch those allocations (and the paired `free` calls on the same objects) to Ruby's `xmalloc` / `xfree`:
- Triggers a GC sweep on memory pressure before failing, increasing the chance of success.
- Raises `NoMemoryError` (a Ruby exception) instead of returning `NULL`, so the `assert` is no longer needed.
- Keeps Ruby's allocation accounting in sync with the actual heap state.
The remaining raw `calloc` / `realloc` / `free(base)` calls in `array.h` already check for `NULL` and propagate `-1` via the C-style API, so they are left as-is.
Supersedes #175.
Co-authored-by: Cursor <cursoragent@cursor.com>xmalloc / xfree for internal selector allocations.1 parent a0c57a1 commit b91adb8
3 files changed
Lines changed: 8 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
75 | | - | |
| 75 | + | |
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
| |||
139 | 139 | | |
140 | 140 | | |
141 | 141 | | |
142 | | - | |
143 | | - | |
| 142 | + | |
| 143 | + | |
144 | 144 | | |
145 | 145 | | |
146 | 146 | | |
| |||
166 | 166 | | |
167 | 167 | | |
168 | 168 | | |
169 | | - | |
| 169 | + | |
170 | 170 | | |
171 | 171 | | |
172 | 172 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
246 | 246 | | |
247 | 247 | | |
248 | 248 | | |
249 | | - | |
250 | | - | |
| 249 | + | |
| 250 | + | |
251 | 251 | | |
252 | 252 | | |
253 | 253 | | |
| |||
268 | 268 | | |
269 | 269 | | |
270 | 270 | | |
271 | | - | |
| 271 | + | |
272 | 272 | | |
273 | 273 | | |
274 | 274 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
0 commit comments