From 05539a72befc2e50f8b0437b69dee64b46b97aa8 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Wed, 7 Jul 2021 22:30:43 -0500 Subject: [PATCH] PrimeField: plug memory leaks --- phpseclib/Math/PrimeField.php | 8 ++++++++ phpseclib/Math/PrimeField/Integer.php | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/phpseclib/Math/PrimeField.php b/phpseclib/Math/PrimeField.php index 6b85c724..7e15f906 100644 --- a/phpseclib/Math/PrimeField.php +++ b/phpseclib/Math/PrimeField.php @@ -111,4 +111,12 @@ class PrimeField extends FiniteField { return Integer::getModulo($this->instanceID)->getLength(); } + + /** + * Destructor + */ + public function __destruct() + { + Integer::cleanupCache($this->instanceID); + } } \ No newline at end of file diff --git a/phpseclib/Math/PrimeField/Integer.php b/phpseclib/Math/PrimeField/Integer.php index c274ff64..c933f5c1 100644 --- a/phpseclib/Math/PrimeField/Integer.php +++ b/phpseclib/Math/PrimeField/Integer.php @@ -95,6 +95,15 @@ class Integer extends Base } } + /** + * Delete the modulo for a given instance + */ + public static function cleanupCache($instanceID) + { + unset(static::$modulo[$instanceID]); + unset(static::$reduce[$instanceID]); + } + /** * Returns the modulo *