Skip to content

Commit f85e595

Browse files
committed
Improve resource management for curl handle
Previous implementation was using its own refcounting (uses field of the php_curl struct). zend_list_add/remove already implements its own refcount, so we don't need to use an other one.
1 parent c4f2a20 commit f85e595

File tree

3 files changed

+6
-19
lines changed

3 files changed

+6
-19
lines changed

ext/curl/interface.c

+2-9
Original file line numberDiff line numberDiff line change
@@ -1952,8 +1952,6 @@ PHP_FUNCTION(curl_init)
19521952
ch->handlers->read->method = PHP_CURL_DIRECT;
19531953
ch->handlers->write_header->method = PHP_CURL_IGNORE;
19541954

1955-
ch->uses = 0;
1956-
19571955
MAKE_STD_ZVAL(clone);
19581956
ch->clone = clone;
19591957

@@ -1995,8 +1993,7 @@ PHP_FUNCTION(curl_copy_handle)
19951993
TSRMLS_SET_CTX(dupch->thread_ctx);
19961994

19971995
dupch->cp = cp;
1998-
dupch->uses = 0;
1999-
ch->uses++;
1996+
zend_list_addref(Z_LVAL_P(zid));
20001997
if (ch->handlers->write->stream) {
20011998
Z_ADDREF_P(ch->handlers->write->stream);
20021999
}
@@ -3210,11 +3207,7 @@ PHP_FUNCTION(curl_close)
32103207
return;
32113208
}
32123209

3213-
if (ch->uses) {
3214-
ch->uses--;
3215-
} else {
3216-
zend_list_delete(Z_LVAL_P(zid));
3217-
}
3210+
zend_list_delete(Z_LVAL_P(zid));
32183211
}
32193212
/* }}} */
32203213

ext/curl/multi.c

+4-9
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ PHP_FUNCTION(curl_multi_add_handle)
8686
ZEND_FETCH_RESOURCE(ch, php_curl *, &z_ch, -1, le_curl_name, le_curl);
8787

8888
_php_curl_cleanup_handle(ch);
89-
ch->uses++;
9089

9190
/* we want to create a copy of this zval that we store in the multihandle structure element "easyh" */
9291
tmp_val = *z_ch;
@@ -113,11 +112,7 @@ void _php_curl_multi_cleanup_list(void *data) /* {{{ */
113112
return;
114113
}
115114

116-
if (ch->uses) {
117-
ch->uses--;
118-
} else {
119-
zend_list_delete(Z_LVAL_P(z_ch));
120-
}
115+
zend_list_delete(Z_LVAL_P(z_ch));
121116
}
122117
/* }}} */
123118

@@ -146,12 +141,12 @@ PHP_FUNCTION(curl_multi_remove_handle)
146141
ZEND_FETCH_RESOURCE(mh, php_curlm *, &z_mh, -1, le_curl_multi_handle_name, le_curl_multi_handle);
147142
ZEND_FETCH_RESOURCE(ch, php_curl *, &z_ch, -1, le_curl_name, le_curl);
148143

149-
--ch->uses;
150144

145+
146+
RETVAL_LONG((long) curl_multi_remove_handle(mh->multi, ch->cp));
151147
zend_llist_del_element( &mh->easyh, &z_ch,
152148
(int (*)(void *, void *)) curl_compare_resources );
153-
154-
RETURN_LONG((long) curl_multi_remove_handle(mh->multi, ch->cp));
149+
155150
}
156151
/* }}} */
157152

ext/curl/php_curl.h

-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ typedef struct {
169169
CURL *cp;
170170
php_curl_handlers *handlers;
171171
long id;
172-
unsigned int uses;
173172
zend_bool in_callback;
174173
zval *clone;
175174
} php_curl;

0 commit comments

Comments
 (0)