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

From: Date: Fri, 06 Nov 2009 20:20:11 +0000
Subject: #50104 [Opn->Fbk]: $dbidx is not being closed in /include/ip-to-country.inc
References: 1  Groups: php.webmaster 
Request: Send a blank email to php-webmaster+get-6394@lists.php.net to get a copy of this message
ID: 50104 Updated by: bjori@php.net Reported By: ignas2526 at gmail dot com -Status: Open +Status: Feedback Bug Type: Website problem PHP Version: Irrelevant New Comment: Does it matter? $dbidx will get closed during RSHUTDOWN anyway...? Previous Comments: ------------------------------------------------------------------------ [2009-11-06 19:55:20] ignas2526 at gmail dot com 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 this bug report at http://bugs.php.net/?id=50104&edit=1

« previous php.webmaster (#6394) next »