This repository was archived by the owner on Aug 31, 2021. It is now read-only.
Commit b62fad6
committed
[Bug 18925] libfoundation: Prevent stack overflow on 2+ OOMs
The stack trace attached to bug 18925 shows the following calls
occurring recursively until stack overflow:
...
MCMemoryNew()
__MCValueCreate()
MCErrorCreateWithMessage()
MCErrorThrowOutOfMemory()
MCMemoryNew()
...
`MCInitialize()` allocates the error structure for use during OOM into
a global. Originally, `MCErrorThrowOutOfMemory()` did two things that
seemed sensible:
- if there was no OOM error structure, it would attempt to create one,
and if that failed, it would exit
- after using the global OOM structure, it would clear it
Unfortunately, this meant that the first OOM that occurred during each
run would be fine -- because there would be a preallocated OOM error
structure -- but on second and subsequent OOM events, the global
structure would be nil.
Attempting to allocate the error would cause a recursive invocation of
`MCMemoryNew()`, which would fail and attempt to throw an OOM error,
which would try to allocate an error, etc.
This patch ensures that `MCErrorThrowOutOfMemory()` never tries to
create a new OOM error structure, and simply immediately aborts if one
is unavailable. Rather than clearing the global, it keeps it around
for subsequent use.1 parent c303a65 commit b62fad6
File tree
2 files changed
+9
-9
lines changed- docs/notes
- libfoundation/src
2 files changed
+9
-9
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
397 | 397 | | |
398 | 398 | | |
399 | 399 | | |
400 | | - | |
401 | | - | |
| 400 | + | |
402 | 401 | | |
403 | | - | |
404 | | - | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
405 | 408 | | |
406 | 409 | | |
407 | | - | |
408 | | - | |
409 | | - | |
410 | | - | |
411 | | - | |
| 410 | + | |
412 | 411 | | |
413 | 412 | | |
414 | 413 | | |
| |||
0 commit comments