From: Yuri Astrakhan Date: Sat, 7 Jul 2007 03:04:20 +0000 (+0000) Subject: filerepo: fixed mem leak for history lines and exposed repository name X-Git-Tag: 1.31.0-rc.0~52228 X-Git-Url: https://git.cyclocoop.org/%27.%24link.%27?a=commitdiff_plain;h=a863e2bee33684226c332ce353199b2d7008941f;p=lhc%2Fweb%2Fwiklou.git filerepo: fixed mem leak for history lines and exposed repository name --- diff --git a/includes/ImagePage.php b/includes/ImagePage.php index 0ded578b84..3265b7f386 100644 --- a/includes/ImagePage.php +++ b/includes/ImagePage.php @@ -460,6 +460,8 @@ EOT } else { $s=''; } $wgOut->addHTML( $s ); + $this->img->resetHistory(); // free db resources + # Exist check because we don't want to show this on pages where an image # doesn't exist along with the noimage message, that would suck. -ævar if( $wgUseExternalEditor && $this->img->exists() ) { diff --git a/includes/filerepo/File.php b/includes/filerepo/File.php index 5a847636f0..90937d2997 100644 --- a/includes/filerepo/File.php +++ b/includes/filerepo/File.php @@ -623,7 +623,8 @@ abstract class File { } /** - * Reset the history pointer to the first element of the history + * Reset the history pointer to the first element of the history. + * Always call this function after using nextHistoryLine() to free db resources * STUB * Overridden in LocalFile. */ @@ -829,7 +830,16 @@ abstract class File { * @return bool */ function isLocal() { - return $this->repo && $this->repo->getName() == 'local'; + return $this->getRepoName() == 'local'; + } + + /** + * Returns the name of the repository. + * + * @return string + */ + function getRepoName() { + return $this->repo ? $this->repo->getName() : 'unknown'; } /** diff --git a/includes/filerepo/LocalFile.php b/includes/filerepo/LocalFile.php index 1f796e5d5c..3f25d91fd7 100644 --- a/includes/filerepo/LocalFile.php +++ b/includes/filerepo/LocalFile.php @@ -78,6 +78,7 @@ class LocalFile extends File parent::__construct( $title, $repo ); $this->metadata = ''; $this->historyLine = 0; + $this->historyRes = null; $this->dataLoaded = false; } @@ -552,9 +553,12 @@ class LocalFile extends File __METHOD__ ); if ( 0 == $dbr->numRows( $this->historyRes ) ) { + $dbr->freeResult($this->historyRes); + $this->historyRes = null; return FALSE; } } else if ( $this->historyLine == 1 ) { + $dbr->freeResult($this->historyRes); $this->historyRes = $dbr->select( 'oldimage', array( 'oi_size AS img_size', @@ -582,6 +586,10 @@ class LocalFile extends File */ function resetHistory() { $this->historyLine = 0; + if (!is_null($this->historyRes)) { + $this->repo->getSlaveDB()->freeResult($this->historyRes); + $this->historyRes = null; + } } /** getFullPath inherited */