Skip to content

Commit 8d7c8fb

Browse files
authored
Fix memory leak (#128)
* Fix memory leak * typo
1 parent 08e3d39 commit 8d7c8fb

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/Promise.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,15 @@ private static function callHandler($index, $value, array $handler)
193193

194194
try {
195195
if (isset($handler[$index])) {
196-
$promise->resolve($handler[$index]($value));
196+
/*
197+
* If $f throws an exception, then $handler will be in the exception
198+
* stack trace. Since $handler contains a reference to the callable
199+
* itself we get a circular reference. We clear the $handler
200+
* here to avoid that memory leak.
201+
*/
202+
$f = $handler[$index];
203+
unset($handler);
204+
$promise->resolve($f($value));
197205
} elseif ($index === 1) {
198206
// Forward resolution values as-is.
199207
$promise->resolve($value);

0 commit comments

Comments
 (0)