From:
Operating system: Windows 2003
PHP version: 5.2.13
Package: ODBC related
Bug Type: Bug
Bug description:Memory Leak in odbc_result with long varchar columns
Description:
------------
When assigning the value returned from odbc_result to a variable and the
result value size is less than the current odbc_longreadlen size, the full
longreadlen memory amount is allocated instead of the smaller amount.
To fix this, if SQLGetData returns SQL_SUCCESS, we can use the length in
vallen to reallocate the memory for field to vallen, i.e. inserting the
lines
} else if (rc == SQL_SUCCESS) {
field = erealloc(field, result->values[field_ind].vallen);
after the rc == SQL_NO_DATA_FOUND check. I've included a patch file, but
I'm not sure if I created that correctly. I've recompiled with this patch
and the bug appears to be fixed.
Test script:
---------------
<?php
ini_set("memory_limit","1048576");
ini_set( "odbc.defaultlrl", "4096" );
$data = '0';
$db = odbc_connect('DSN', 'user', 'pass');
odbc_exec($db, 'CREATE TABLE Temp (contents long varchar)');
odbc_exec($db, 'INSERT INTO Temp (contents) VALUES (\'' . $data . '\')');
$rst = odbc_exec($db, 'select * from Temp');
$contentArray = Array();
for($i = 0; $i < 1024; $i++){
odbc_fetch_row($rst,1);
$contentArray[] = odbc_result($rst, 'contents');
}
odbc_free_result($rst);
echo count($contentArray);
?>
Expected result:
----------------
1024
Actual result:
--------------
Fatal error: Allowed memory size of 1048576 bytes exhausted (tried to
allocate 4096 bytes) in D:\memLeakTest.php on line 12
--
Edit bug report at http://bugs.php.net/bug.php?id=51606&edit=1
--
Try a snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=51606&r=trysnapshot52
Try a snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=51606&r=trysnapshot53
Try a snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=51606&r=trysnapshot60
Fixed in SVN:
http://bugs.php.net/fix.php?id=51606&r=fixed
Fixed in SVN and need be documented:
http://bugs.php.net/fix.php?id=51606&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=51606&r=alreadyfixed
Need backtrace:
http://bugs.php.net/fix.php?id=51606&r=needtrace
Need Reproduce Script:
http://bugs.php.net/fix.php?id=51606&r=needscript
Try newer version:
http://bugs.php.net/fix.php?id=51606&r=oldversion
Not developer issue:
http://bugs.php.net/fix.php?id=51606&r=support
Expected behavior:
http://bugs.php.net/fix.php?id=51606&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=51606&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=51606&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=51606&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=51606&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=51606&r=dst
IIS Stability:
http://bugs.php.net/fix.php?id=51606&r=isapi
Install GNU Sed:
http://bugs.php.net/fix.php?id=51606&r=gnused
Floating point limitations:
http://bugs.php.net/fix.php?id=51606&r=float
No Zend Extensions:
http://bugs.php.net/fix.php?id=51606&r=nozend
MySQL Configuration Error:
http://bugs.php.net/fix.php?id=51606&r=mysqlcfg