Ver Fonte

Merge pull request #191 from 2276225819/patch-2

fix memory leak for StreamSelectLoop.php
walkor há 8 anos atrás
pai
commit
50db90651c
1 ficheiros alterados com 4 adições e 2 exclusões
  1. 4 2
      Events/React/StreamSelectLoop.php

+ 4 - 2
Events/React/StreamSelectLoop.php

@@ -56,10 +56,12 @@ class StreamSelectLoop extends \React\EventLoop\StreamSelectLoop
                 $this->_timerIdMap[++$this->_timerIdIndex] = $timer_obj;
                 return $this->_timerIdIndex;
             case EventInterface::EV_TIMER_ONCE:
-                $timer_obj = $this->addTimer($fd, function() use ($func, $args) {
+                $index = ++$this->_timerIdIndex;
+                $timer_obj = $this->addTimer($fd, function() use ($func, $args, $index) {
+                    $this->del($index,EventInterface::EV_TIMER_ONCE);
                     call_user_func_array($func, $args);
                 });
-                $this->_timerIdMap[++$this->_timerIdIndex] = $timer_obj;
+                $this->_timerIdMap[$index] = $timer_obj;
                 return $this->_timerIdIndex;
         }
         return false;