|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2008-11-28 16:03 UTC] thomas at koch dot ro
Description:
------------
Setting cURL options in a foreach leaks memory
Reproduce code:
---------------
$ch = curl_init();
$opt = array(
CURLOPT_AUTOREFERER => TRUE,
CURLOPT_BINARYTRANSFER => TRUE
);
// This works fine:
//curl_setopt( $ch, CURLOPT_AUTOREFERER , TRUE );
//curl_setopt( $ch, CURLOPT_BINARYTRANSFER , TRUE );
// setting the options in a foreach leads to memory leaks
foreach( $opt as $option => $value ) {
curl_setopt( $ch, $option, $value );
}
Expected result:
----------------
no output
Actual result:
--------------
[Fri Nov 28 17:01:18 2008] Script: '/home/ymc-toko/curl_bug.php'
/var/checkouts/php5_3/ext/curl/interface.c(1505) : Freeing 0x030C6BE8 (32 bytes), script=/home/ymc-toko/curl_bug.php
[Fri Nov 28 17:01:18 2008] Script: '/home/ymc-toko/curl_bug.php'
/var/checkouts/php5_3/ext/curl/interface.c(1397) : Freeing 0x030C6C68 (32 bytes), script=/home/ymc-toko/curl_bug.php
=== Total 2 memory leaks detected ===
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 21:00:01 2025 UTC |
Just for info, I believe there's a bug somewhere. After the foreach() loop, $opt looks like this: array(2) { [58]=> NULL [19914]=> bool(true) } Assigning $value by reference in the foreach makes the bug disappear. I had a look at xml_parser_set_option() (similar function) and tried to make curl_set_opt() use the same way to get args, it seems to have fixed the problem (haven't played enough with ZE yet to know for sure if it's the correct fix). Patch: http://ookoo.org/svn/snip/php-5.3.0alpha3_curl_mem_bug.patch