Fix PHP memory leak in file_get_contents()
* ref https://bugs.php.net/bug.php?id=61961 * ref https://github.com/owncloud/core/issues/20261#issuecomment-180000256 * code is based on the proposal of @chriseqipe * fixes #20261
This commit is contained in:
parent
f6cea3c9c4
commit
6ecd1d9e86
|
@ -90,7 +90,7 @@ class OC_FileChunking {
|
||||||
* Assembles the chunks into the file specified by the path.
|
* Assembles the chunks into the file specified by the path.
|
||||||
* Chunks are deleted afterwards.
|
* Chunks are deleted afterwards.
|
||||||
*
|
*
|
||||||
* @param string $f target path
|
* @param resource $f target path
|
||||||
*
|
*
|
||||||
* @return integer assembled file size
|
* @return integer assembled file size
|
||||||
*
|
*
|
||||||
|
@ -106,6 +106,8 @@ class OC_FileChunking {
|
||||||
// remove after reading to directly save space
|
// remove after reading to directly save space
|
||||||
$cache->remove($prefix.$i);
|
$cache->remove($prefix.$i);
|
||||||
$count += fwrite($f, $chunk);
|
$count += fwrite($f, $chunk);
|
||||||
|
// let php release the memory to work around memory exhausted error with php 5.6
|
||||||
|
$chunk = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $count;
|
return $count;
|
||||||
|
|
|
@ -176,7 +176,12 @@ class Local extends \OC\Files\Storage\Common {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function file_get_contents($path) {
|
public function file_get_contents($path) {
|
||||||
return file_get_contents($this->getSourcePath($path));
|
// file_get_contents() has a memory leak: https://bugs.php.net/bug.php?id=61961
|
||||||
|
$filename = $this->getSourcePath($path);
|
||||||
|
$handle = fopen($filename,'rb');
|
||||||
|
$content = fread($handle, filesize($filename));
|
||||||
|
fclose($handle);
|
||||||
|
return $content;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function file_put_contents($path, $data) {
|
public function file_put_contents($path, $data) {
|
||||||
|
|
Loading…
Reference in New Issue