php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #51606 Memory Leak in odbc_result with long varchar columns
Submitted: 2010-04-19 21:56 UTC Modified: 2013-02-18 00:34 UTC
Votes:9
Avg. Score:4.6 ± 0.8
Reproduced:6 of 6 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (16.7%)
From: arobins at csg dot uwaterloo dot ca Assigned:
Status: No Feedback Package: ODBC related
PHP Version: 5.2.13 OS: Windows 2003
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: arobins at csg dot uwaterloo dot ca
New email:
PHP Version: OS:

 

 [2010-04-19 21:56 UTC] 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


Patches

odbc_result_long_memory_leak_fix (last revision 2010-04-19 19:57 UTC by arobins at csg dot uwaterloo dot ca)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-11-06 16:41 UTC] felipe@php.net
-Status: Open +Status: Feedback
 [2010-11-06 16:41 UTC] felipe@php.net
Please try using this snapshot:

  http://snaps.php.net/php5.3-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/


 [2013-02-18 00:34 UTC] 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.
 [2014-12-26 15:55 UTC] pravdin dot alex at gmail dot com
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 ...
 [2015-02-19 16:06 UTC] sinasalek at gmail dot com
Having the exact same problem on Ubuntu 14 LTS 64bit, PHP 5.6.5, Microsoft Native Client 11.
Also there is another bug report here Bug #67437
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 04:01:27 2024 UTC