mirror of
https://github.com/phpseclib/phpseclib.git
synced 2025-02-02 20:08:29 +00:00
SSH2: use weakreference when available to stop memory leak
This commit is contained in:
parent
f1c4164687
commit
418035c404
@ -1123,7 +1123,7 @@ class SSH2
|
|||||||
31 => 'NET_SSH2_MSG_KEX_ECDH_REPLY']
|
31 => 'NET_SSH2_MSG_KEX_ECDH_REPLY']
|
||||||
);
|
);
|
||||||
|
|
||||||
self::$connections[$this->getResourceId()] = $this;
|
self::$connections[$this->getResourceId()] = class_exists('WeakReference') ? \WeakReference::create($this) : $this;
|
||||||
|
|
||||||
if (is_resource($host)) {
|
if (is_resource($host)) {
|
||||||
$this->fsock = $host;
|
$this->fsock = $host;
|
||||||
@ -4896,7 +4896,10 @@ class SSH2
|
|||||||
*/
|
*/
|
||||||
public static function getConnectionByResourceId($id)
|
public static function getConnectionByResourceId($id)
|
||||||
{
|
{
|
||||||
return isset(self::$connections[$id]) ? self::$connections[$id] : false;
|
if (isset(self::$connections[$id])) {
|
||||||
|
return self::$connections[$id] instanceof \WeakReference ? self::$connections[$id]->get() : self::$connections[$id];
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -4906,7 +4909,14 @@ class SSH2
|
|||||||
*/
|
*/
|
||||||
public static function getConnections()
|
public static function getConnections()
|
||||||
{
|
{
|
||||||
return self::$connections;
|
if (!class_exists('WeakReference')) {
|
||||||
|
return self::$connections;
|
||||||
|
}
|
||||||
|
$temp = [];
|
||||||
|
foreach (self::$connections as $key=>$ref) {
|
||||||
|
$temp[$key] = $ref->get();
|
||||||
|
}
|
||||||
|
return $temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user