Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:45029 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 93597 invoked from network); 18 Jul 2009 16:03:21 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Jul 2009 16:03:21 -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.237 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.237 rv-out-0506.google.com Received: from [209.85.198.237] ([209.85.198.237:23504] helo=rv-out-0506.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 28/4B-02180-842F16A4 for ; Sat, 18 Jul 2009 12:03:21 -0400 Received: by rv-out-0506.google.com with SMTP id l9so391810rvb.23 for ; Sat, 18 Jul 2009 09:03:18 -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:cc:subject:references:in-reply-to :content-type; bh=6Xt96+69cdIyvQimaZF6ghSlhrq85sQM+Lupbns98Zs=; b=PDKq6gjIGa5mnn3URrB9Z5Tepb5HO8Ln8rD3YtvR/Qs1OjpmQ8MurDSW7b4FzzRZgl QcM48s5v3bhCvfDwelQhabMHXAfF98kHRiGBLHaVdMIdJj0oWoDLnSegViWxRyhfQ/X/ MZ0vyc7arClDrBt4v6KH9qLmpBFxCS4wa3Nzs= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type; b=vZ6dbN5zAgKTlR8b40tnwa4h/AokhpRbigrhJyMjSRAViV+SBfFST4J53zE4/d5unZ MrRkn0w5db/2PakU1jvdgG7I93Mo6c5s1RAtF8UeLhmGReUN4ZQOX2X6stBknr4xCo0M kH3je5gEFeivtDbGUL1DKsIfLEibfswQfh2nI= Received: by 10.140.192.18 with SMTP id p18mr1527696rvf.95.1247932998284; Sat, 18 Jul 2009 09:03:18 -0700 (PDT) Received: from SriramNatarajan-MacBook.local (sca-ea-fw-1.Sun.COM [192.18.43.225]) by mx.google.com with ESMTPS id l31sm13407935rvb.43.2009.07.18.09.03.15 (version=SSLv3 cipher=RC4-MD5); Sat, 18 Jul 2009 09:03:16 -0700 (PDT) Message-ID: <4A61F243.7040902@GMail.COM> Date: Sat, 18 Jul 2009 09:03:15 -0700 User-Agent: Thunderbird 2.0.0.22 (Macintosh/20090605) MIME-Version: 1.0 To: jani.taskinen@iki.fi CC: PHP internals References: <4A616EFE.7090107@GMail.COM> <4A6189AF.6040001@sci.fi> In-Reply-To: <4A6189AF.6040001@sci.fi> Content-Type: multipart/mixed; boundary="------------050602070901020402030304" Subject: Re: [PHP-DEV] PATCH for bug 48774 From: sriram.natarajan@gmail.com (Sriram Natarajan) --------------050602070901020402030304 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Jani Taskinen wrote: > Sriram Natarajan wrote: >> 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 ? >> >> >> > Fix your whitespace first. We use tabs only in .c files.. > Please find the updated patch below --------------050602070901020402030304 Content-Type: text/plain; x-mac-type="0"; x-mac-creator="0"; name="patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="patch" --- interface.c.ORIG 2009-07-09 15:24:00.000000000 -0700 +++ interface.c 2009-07-15 16:34:17.000000000 -0700 @@ -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,8 +2306,19 @@ #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); --- php_curl.h.ORIG 2009-07-14 23:42:08.000000000 -0700 +++ php_curl.h 2009-07-15 15:25:34.000000000 -0700 @@ -139,6 +139,7 @@ long id; unsigned int uses; zend_bool in_callback; + zval *clone; } php_curl; typedef struct { --- /dev/null 2009-05-08 12:42:52.457160733 -0700 +++ tests/curl_copy_handle_basic_007.phpt 2009-07-14 17:40:47.000000000 -0700 @@ -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=== --------------050602070901020402030304--