#50104 [NEW]: $dbidx is not being closed in /include/ip-to-country.inc

From: Date: Fri, 06 Nov 2009 19:55:21 +0000
Subject: #50104 [NEW]: $dbidx is not being closed in /include/ip-to-country.inc
Groups: php.webmaster 
Request: Send a blank email to php-webmaster+get-6393@lists.php.net to get a copy of this message
From: ignas2526 at gmail dot com Operating system: PHP version: Irrelevant PHP Bug Type: Website problem Bug description: $dbidx is not being closed in /include/ip-to-country.inc Description: ------------ The fopened /backend/ip-to-country.idx in i2c_search_in_index function isn't fclosed anywhere. Reproduce code: --------------- http://lt2.php.net/source.php?url=/include/ip-to-country.inc i2c_search_in_index function. Expected result: ---------------- function i2c_search_in_index($ip) { // Indexed part and record number to jump to $idxpart = 0; $recnum = 0; // Open the index file for reading $dbidx = fopen( $_SERVER['DOCUMENT_ROOT'] . "/backend/ip-to-country.idx", "r" ); if (!$dbidx) { return FALSE; } // Read in granularity from index file and // convert current IP to something useful $granularity = intval(fgets($dbidx, 64)); $ip_chunk = intval($ip / $granularity); // Loop till we can read the file while (!feof($dbidx)) { // Get CSV data from index file $data = fgetcsv($dbidx, 100); // Compare current index part with our IP if ($ip_chunk >= $idxpart && $ip_chunk < (int) $data[0]) { return array($recnum, (int) $data[1]); } // Store for next compare $idxpart = (int) $data[0]; $recnum = (int) $data[1]; } // Close indexfile fclose($dbidx); // Return record number found return array($recnum, -1); } Actual result: -------------- function i2c_search_in_index($ip) { // Indexed part and record number to jump to $idxpart = 0; $recnum = 0; // Open the index file for reading $dbidx = fopen( $_SERVER['DOCUMENT_ROOT'] . "/backend/ip-to-country.idx", "r" ); if (!$dbidx) { return FALSE; } // Read in granularity from index file and // convert current IP to something useful $granularity = intval(fgets($dbidx, 64)); $ip_chunk = intval($ip / $granularity); // Loop till we can read the file while (!feof($dbidx)) { // Get CSV data from index file $data = fgetcsv($dbidx, 100); // Compare current index part with our IP if ($ip_chunk >= $idxpart && $ip_chunk < (int) $data[0]) { return array($recnum, (int) $data[1]); } // Store for next compare $idxpart = (int) $data[0]; $recnum = (int) $data[1]; } // Return record number found return array($recnum, -1); } -- Edit bug report at http://bugs.php.net/?id=50104&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=50104&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=50104&r=trysnapshot53 Try a snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=50104&r=trysnapshot60 Fixed in SVN: http://bugs.php.net/fix.php?id=50104&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=50104&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=50104&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=50104&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=50104&r=needscript Try newer version: http://bugs.php.net/fix.php?id=50104&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=50104&r=support Expected behavior: http://bugs.php.net/fix.php?id=50104&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=50104&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=50104&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=50104&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=50104&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=50104&r=dst IIS Stability: http://bugs.php.net/fix.php?id=50104&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=50104&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=50104&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=50104&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=50104&r=mysqlcfg

« previous php.webmaster (#6393) next »