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.
This commit is contained in:
Dylan K. Taylor 2023-08-09 13:28:05 +01:00
parent d88c3d8ced
commit b4c5f5d58d
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -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");