From b4c5f5d58dcbd28d76d9a89b4d0e1346cd97e2d1 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 9 Aug 2023 13:28:05 +0100 Subject: [PATCH] PluginBase: fixed resource leak all this time we've been harping at plugin devs to fix their own leaks, and here's one right under our noses that no one spotted for 10 years ... this leak is rather common, since it will occur whenever a plugin attempts to save a resource which already exists in the data folder. This bug was introduced in 2014 by commit 63288346814b7b827f1f7cc7a16419af43bd0bfa. --- src/plugin/PluginBase.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/plugin/PluginBase.php b/src/plugin/PluginBase.php index c8f3e1c39..23a98b943 100644 --- a/src/plugin/PluginBase.php +++ b/src/plugin/PluginBase.php @@ -226,19 +226,19 @@ abstract class PluginBase implements Plugin, CommandExecutor{ return false; } + $out = Path::join($this->dataFolder, $filename); + if(file_exists($out) && !$replace){ + return false; + } + if(($resource = $this->getResource($filename)) === null){ return false; } - $out = Path::join($this->dataFolder, $filename); if(!file_exists(dirname($out))){ mkdir(dirname($out), 0755, true); } - if(file_exists($out) && !$replace){ - return false; - } - $fp = fopen($out, "wb"); if($fp === false) throw new AssumptionFailedError("fopen() should not fail with wb flags");