Skip to content

Commit 2d9bc88

Browse files
committed
Fixed clone refcount
1 parent 564db38 commit 2d9bc88

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

ext/curl/interface.c

+6-4
Original file line numberDiff line numberDiff line change
@@ -1980,7 +1980,7 @@ PHP_FUNCTION(curl_copy_handle)
19801980
dupch->to_free = ch->to_free;
19811981

19821982
/* Keep track of cloned copies to avoid invoking curl destructors for every clone */
1983-
ZVAL_COPY(&dupch->clone, &ch->clone);
1983+
ch->clone++;
19841984

19851985
ZEND_REGISTER_RESOURCE(return_value, dupch, le_curl);
19861986
dupch->res = Z_RES_P(return_value);
@@ -2583,8 +2583,10 @@ static int _php_curl_setopt(php_curl *ch, long option, zval *zvalue TSRMLS_DC) /
25832583
return FAILURE;
25842584
}
25852585

2586-
if (Z_REFCOUNTED(ch->clone) && Z_REFCOUNT(ch->clone) <= 1) {
2586+
if (ch->clone == 0) {
25872587
zend_llist_clean(&ch->to_free->post);
2588+
} else {
2589+
--ch->clone;
25882590
}
25892591
zend_llist_add_element(&ch->to_free->post, &first);
25902592
error = curl_easy_setopt(ch->cp, CURLOPT_HTTPPOST, first);
@@ -3167,14 +3169,14 @@ static void _php_curl_close_ex(php_curl *ch TSRMLS_DC)
31673169
curl_easy_cleanup(ch->cp);
31683170

31693171
/* cURL destructors should be invoked only by last curl handle */
3170-
if (Z_ISUNDEF(ch->clone)) {
3172+
if (ch->clone == 0) {
31713173
zend_llist_clean(&ch->to_free->str);
31723174
zend_llist_clean(&ch->to_free->post);
31733175
zend_hash_destroy(ch->to_free->slist);
31743176
efree(ch->to_free->slist);
31753177
efree(ch->to_free);
31763178
} else {
3177-
//??? Z_DELREF(ch->clone);
3179+
--ch->clone;
31783180
}
31793181

31803182
smart_str_free(&ch->handlers->write->buf);

ext/curl/php_curl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ typedef struct {
180180
php_curl_handlers *handlers;
181181
zend_resource *res;
182182
zend_bool in_callback;
183-
zval clone;
183+
zend_uint clone;
184184
zend_bool safe_upload;
185185
} php_curl;
186186

0 commit comments

Comments
 (0)