-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix uouv on oom on object allocation
We should initialize object handlers before trying to allocate more memory, because if we OOM we'll look for the free_obj handler which has not been initialized. Furthermore, free_obj can run before the object is fully initialized, requiring guards for potentially unset fields. Fixes GH-11734
- Loading branch information
Showing
3 changed files
with
45 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
ini_set('memory_limit', '1M'); | ||
|
||
$class = $argv[1]; | ||
$objects = []; | ||
|
||
try { | ||
while (true) { | ||
$rc = new ReflectionClass($class); | ||
$objects[] = $rc->newInstanceWithoutConstructor(); | ||
} | ||
} catch (Throwable) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
--TEST-- | ||
Test OOM on new of each class | ||
--SKIPIF-- | ||
<?php | ||
if (getenv("SKIP_SLOW_TESTS")) die('skip slow test'); | ||
?> | ||
--FILE-- | ||
<?php | ||
|
||
$file = __DIR__ . '/new_oom.inc'; | ||
$php = PHP_BINARY; | ||
|
||
foreach (get_declared_classes() as $class) { | ||
$output = shell_exec("$php $file $class"); | ||
if ($output && preg_match('(^\nFatal error: Allowed memory size of [0-9]+ bytes exhausted[^\r\n]* \(tried to allocate [0-9]+ bytes\) in [^\r\n]+ on line [0-9]+$)', $output) !== 1) { | ||
echo "Class $class failed\n"; | ||
echo $output; | ||
} | ||
} | ||
|
||
?> | ||
===DONE=== | ||
--EXPECT-- | ||
===DONE=== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters