Re: Curl POST emalloc leak?

From: Date: Sun, 18 May 2008 23:03:13 +0000
Subject: Re: Curl POST emalloc leak?
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-37711@lists.php.net to get a copy of this message
Cristian Rodríguez wrote:
Rasmus Lerdorf escribió:
Can someone spot why this code (tested in both 5.2.5 and 5.3) <?php function curl($post) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "www.fdhfkdsslak.bogus"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); if($post) {
    curl_setopt($ch, CURLOPT_POST, 1);
    for($args='',$i=0;$i<75;$i++) $args .= "a=$i&";
    curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
    unset($args);
} curl_exec($ch); curl_close($ch); } echo "start ".memory_get_usage()."\n"; for($i=0;$i<10;$i++) { curl(0); echo "GET ".memory_get_usage()."\n"; } for($i=0;$i<10;$i++) { curl(1); echo "POST ".memory_get_usage()."\n"; } ?> outputs:
for me start 120400 GET 122624 GET 122624 GET 122624 GET 122624 GET 122624 GET 122624 GET 122624 GET 122624 GET 122624 GET 122624 POST 124968 POST 125928 POST 126608 POST 127272 POST 127920 POST 128552 POST 129168 POST 129768 POST 130352 POST 130920 when I request for $real_usage the results are constant..
Yes, I'm not saying there is a malloc leak. I haven't seen that, but the emalloc leak means that eventually a script that repeatedly sends post requests is going to hit the memory limit no matter how much cleanup it does. Note that you don't actually need to send the request. It looks like repeatedly doing: $ch = curl_init(); curl_setopt($ch, CURLOPT_POSTFIELDS, $args); curl_close($ch); Is enough to do it. Still looking at the code. Seems like zend_llist_clean(&ch->to_free.str); isn't doing the right thing somehow. -Rasmus

« previous php.internals (#37711) next »