Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:45027 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 31143 invoked from network); 18 Jul 2009 06:43:17 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Jul 2009 06:43:17 -0000 Authentication-Results: pb1.pair.com smtp.mail=sriram.natarajan@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=sriram.natarajan@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.198.230 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: sriram.natarajan@gmail.com X-Host-Fingerprint: 209.85.198.230 rv-out-0506.google.com Received: from [209.85.198.230] ([209.85.198.230:61822] helo=rv-out-0506.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 34/8F-02180-30F616A4 for ; Sat, 18 Jul 2009 02:43:16 -0400 Received: by rv-out-0506.google.com with SMTP id l9so335058rvb.23 for ; Fri, 17 Jul 2009 23:43:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:subject:content-type :content-transfer-encoding; bh=lRtc8zThCqDJsTsFFtXudI0VijxiBjSrVVG9zfg45ys=; b=Ny3TugacWr/dTmw3jtu3AvbnkN/g9FnyoT7f6VjtBYxcplOWHWGM+NE239Ya74GLjw wgoje0H5d5OtqBXfP16+pfJHiRURRZyJFwF6Zv/ICLU5mXvoGY/8KDqrw2HzawA7BWmC vbnm6bTZXQ8pcthbuERf0in1eRFg3rtR3vSKY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject :content-type:content-transfer-encoding; b=LjyvvXS052NdJPlzXNPkXwpsQfSMb4g2zJ0iphDGzqUk0UDHLJ0qAlVBLTgu1ww9Nh bM650m/NXK9G8T9F0sBA/5B1IJ47pHX0LhjtYqoSfS+0e6PSv/CGPMTFVYVlaT7Td/6i OhwncjI/k5YLLWnDox59fOq89jtK9+P4971rc= Received: by 10.140.164.20 with SMTP id m20mr1290808rve.143.1247899392873; Fri, 17 Jul 2009 23:43:12 -0700 (PDT) Received: from SriramNatarajan-MacBook.local (sca-ea-fw-1.Sun.COM [192.18.43.225]) by mx.google.com with ESMTPS id l31sm10862022rvb.13.2009.07.17.23.43.11 (version=SSLv3 cipher=RC4-MD5); Fri, 17 Jul 2009 23:43:12 -0700 (PDT) Message-ID: <4A616EFE.7090107@GMail.COM> Date: Fri, 17 Jul 2009 23:43:10 -0700 User-Agent: Thunderbird 2.0.0.22 (Macintosh/20090605) MIME-Version: 1.0 To: PHP internals Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: PATCH for bug 48774 From: sriram.natarajan@gmail.com (Sriram Natarajan) Hi I was looking into CR: 48774(http://bugs.php.net/bug.php?id=48774&thanks=3) and was hoping if some one can kindly review this patch. This patch does address the SEGV issue reported in the bug. Can this be applied to PHP 5.3 and PHP 5.2 as well ? Index: ext/curl/interface.c =================================================================== --- ext/curl/interface.c (revision 284171) +++ ext/curl/interface.c (working copy) @@ -1328,6 +1328,7 @@ { php_curl *ch; CURL *cp; + zval *clone; char *url = NULL; int url_len = 0; @@ -1353,6 +1354,9 @@ ch->uses = 0; + MAKE_STD_ZVAL(clone); + ch->clone = clone; + curl_easy_setopt(ch->cp, CURLOPT_NOPROGRESS, 1); curl_easy_setopt(ch->cp, CURLOPT_VERBOSE, 0); curl_easy_setopt(ch->cp, CURLOPT_ERRORBUFFER, ch->err.str); @@ -1448,6 +1452,10 @@ zend_llist_copy(&dupch->to_free.slist, &ch->to_free.slist); zend_llist_copy(&dupch->to_free.post, &ch->to_free.post); + /* Keep track of cloned copies to avoid invoking curl destructors for every clone */ + Z_ADDREF_P(ch->clone); + dupch->clone = ch->clone; + ZEND_REGISTER_RESOURCE(return_value, dupch, le_curl); dupch->id = Z_LVAL_P(return_value); } @@ -2298,9 +2306,20 @@ #if LIBCURL_VERSION_NUM < 0x071101 zend_llist_clean(&ch->to_free.str); #endif - zend_llist_clean(&ch->to_free.slist); - zend_llist_clean(&ch->to_free.post); + /* cURL destructors should be invoked only by last curl handle */ + if (Z_REFCOUNT_P(ch->clone) <= 1) { + zend_llist_clean(&ch->to_free.slist); + zend_llist_clean(&ch->to_free.post); + zval_ptr_dtor(&ch->clone); + } else { + Z_DELREF_P(ch->clone); + ch->to_free.slist.dtor = NULL; + ch->to_free.post.dtor = NULL; + zend_llist_clean(&ch->to_free.slist); + zend_llist_clean(&ch->to_free.post); + } + if (ch->handlers->write->buf.len > 0) { smart_str_free(&ch->handlers->write->buf); } Index: ext/curl/tests/curl_copy_handle_basic_007.phpt =================================================================== --- ext/curl/tests/curl_copy_handle_basic_007.phpt (revision 0) +++ ext/curl/tests/curl_copy_handle_basic_007.phpt (revision 0) @@ -0,0 +1,44 @@ +--TEST-- +Test curl_copy_handle() with simple POST +--SKIPIF-- + +--FILE-- + "World", "Foo" => "Bar", "Person" => "John Doe")); + curl_setopt($ch, CURLOPT_URL, $url); //set the url we want to use + + $copy = curl_copy_handle($ch); + curl_close($ch); + + $curl_content = curl_exec($copy); + curl_close($copy); + + var_dump( $curl_content ); +?> +===DONE=== +--EXPECTF-- +*** Testing curl copy handle with simple POST using array as arguments *** +string(163) "array(1) { + ["test"]=> + string(7) "getpost" +} +array(3) { + ["Hello"]=> + string(5) "World" + ["Foo"]=> + string(3) "Bar" + ["Person"]=> + string(8) "John Doe" +} +" +===DONE=== Index: ext/curl/php_curl.h =================================================================== --- ext/curl/php_curl.h (revision 284171) +++ ext/curl/php_curl.h (working copy) @@ -139,6 +139,7 @@ long id; unsigned int uses; zend_bool in_callback; + zval *clone; } php_curl; typedef struct { Index: NEWS =================================================================== --- NEWS (revision 284171) +++ NEWS (working copy) @@ -32,6 +32,8 @@ (markril at hotmail dot com, Pierre) - Fixed bug #38091 (Mail() does not use FQDN when sending SMTP helo). (Kalle, Rick Yorgason) +- Fixed bug #48774 (SIGSEGVs when using curl_copy_handle()). + (Sriram Natarajan) 30 Jun 2009, PHP 5.3.0 - Upgraded bundled PCRE to version 7.9. (Nuno) thanks sriram