Skip to content

Commit

Permalink
Fix memory leak (guzzle#128)
Browse files Browse the repository at this point in the history
* Fix memory leak

* typo
  • Loading branch information
Nyholm committed Sep 21, 2020
1 parent 08e3d39 commit 8d7c8fb
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Promise.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,15 @@ private static function callHandler($index, $value, array $handler)

try {
if (isset($handler[$index])) {
$promise->resolve($handler[$index]($value));
/*
* If $f throws an exception, then $handler will be in the exception
* stack trace. Since $handler contains a reference to the callable
* itself we get a circular reference. We clear the $handler
* here to avoid that memory leak.
*/
$f = $handler[$index];
unset($handler);
$promise->resolve($f($value));
} elseif ($index === 1) {
// Forward resolution values as-is.
$promise->resolve($value);
Expand Down

0 comments on commit 8d7c8fb

Please sign in to comment.