filerepo: fixed mem leak for history lines and exposed repository name
authorYuri Astrakhan <yurik@users.mediawiki.org>
Sat, 7 Jul 2007 03:04:20 +0000 (03:04 +0000)
committerYuri Astrakhan <yurik@users.mediawiki.org>
Sat, 7 Jul 2007 03:04:20 +0000 (03:04 +0000)
includes/ImagePage.php
includes/filerepo/File.php
includes/filerepo/LocalFile.php

index 0ded578..3265b7f 100644 (file)
@@ -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() ) {
index 5a84763..90937d2 100644 (file)
@@ -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'; 
        }
 
        /**
index 1f796e5..3f25d91 100644 (file)
@@ -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 */