Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:37711 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 16625 invoked from network); 18 May 2008 23:03:17 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 May 2008 23:03:17 -0000 Authentication-Results: pb1.pair.com smtp.mail=rasmus@lerdorf.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=rasmus@lerdorf.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain lerdorf.com from 204.11.219.139 cause and error) X-PHP-List-Original-Sender: rasmus@lerdorf.com X-Host-Fingerprint: 204.11.219.139 mail.lerdorf.com Received: from [204.11.219.139] ([204.11.219.139:49383] helo=mail.lerdorf.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 64/18-57662-4B5B0384 for ; Sun, 18 May 2008 19:03:17 -0400 Received: from [192.168.200.148] (c-24-6-219-206.hsd1.ca.comcast.net [24.6.219.206]) (authenticated bits=0) by mail.lerdorf.com (8.14.3/8.14.3/Debian-1) with ESMTP id m4IN3Dff001683; Sun, 18 May 2008 16:03:13 -0700 Message-ID: <4830B5B1.70602@lerdorf.com> Date: Sun, 18 May 2008 16:03:13 -0700 User-Agent: Thunderbird 2.0.0.4 (Macintosh/20070604) MIME-Version: 1.0 To: =?UTF-8?B?Q3Jpc3RpYW4gUm9kcsOtZ3Vleg==?= CC: PHP Developers Mailing List References: <482E8391.9080004@lerdorf.com> <48309995.4080409@suse.de> In-Reply-To: <48309995.4080409@suse.de> X-Enigmail-Version: 0.95.6 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Greylist: Sender succeeded SMTP AUTH authentication, not delayed by milter-greylist-3.0 (mail.lerdorf.com [204.11.219.139]); Sun, 18 May 2008 16:03:13 -0700 (PDT) Subject: Re: [PHP-DEV] Curl POST emalloc leak? From: rasmus@lerdorf.com (Rasmus Lerdorf) Cristian Rodríguez wrote: > Rasmus Lerdorf escribió: >> Can someone spot why this code >> >> (tested in both 5.2.5 and 5.3) >> >> > 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