|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
Patchesodbc_result_long_memory_leak_fix (last revision 2010-04-19 19:57 UTC by arobins at csg dot uwaterloo dot ca)Pull RequestsHistoryAllCommentsChangesGit/SVN commits
[2010-11-06 16:41 UTC] felipe@php.net
-Status: Open
+Status: Feedback
[2010-11-06 16:41 UTC] felipe@php.net
[2013-02-18 00:34 UTC] php-bugs at lists dot php dot net
[2014-12-26 15:55 UTC] pravdin dot alex at gmail dot com
[2015-02-19 16:06 UTC] sinasalek at gmail dot com
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Nov 04 17:00:01 2025 UTC |
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