Edit report at http://bugs.php.net/bug.php?id=51606&edit=1
ID: 51606 Updated by: fel...@php.net Reported by: arobins at csg dot uwaterloo dot ca Summary: Memory Leak in odbc_result with long varchar columns -Status: Open +Status: Feedback Type: Bug Package: ODBC related Operating System: Windows 2003 PHP Version: 5.2.13 Block user comment: N New Comment: Please try using this snapshot: http://snaps.php.net/php5.3-latest.tar.gz For Windows: http://windows.php.net/snapshots/ Previous Comments: ------------------------------------------------------------------------ [2010-04-19 21:56:01] arobins at csg dot uwaterloo dot ca 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 this bug report at http://bugs.php.net/bug.php?id=51606&edit=1