Bug #51606 [Com]: Memory Leak in odbc_result with long varchar columns
Edit report at https://bugs.php.net/bug.php?id=51606&edit=1
ID: 51606
Comment by: pravdin dot alex at gmail dot com
Reported by: arobins at csg dot uwaterloo dot ca
Summary: Memory Leak in odbc_result with long varchar columns
Status: No Feedback
Type: Bug
Package: ODBC related
Operating System: Windows 2003
PHP Version: 5.2.13
Block user comment: N
Private report: N
New Comment:
MS SQL 2012 + Ubuntu 14.04 (freeTDS 0.91, linuxODBC) + PHP 5.5.9 (odbc_connect)
Trying to do odbc_fetch_array() on query with select from nvarchar(2000) field
The same error:
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 4294967293 bytes)
in ...
Previous Comments:
------------------------------------------------------------------------
[2013-02-18 00:34:13] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.
------------------------------------------------------------------------
[2010-11-06 16:41:14] felipe@php.net
Please try using this snapshot:
http://snaps.php.net/php5.3-latest.tar.gz
For Windows:
http://windows.php.net/snapshots/
------------------------------------------------------------------------
[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 https://bugs.php.net/bug.php?id=51606&edit=1
Thread (5 messages)