Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
adoy committed Jan 5, 2013
1 parent c4f2a20 commit f85e595
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 19 deletions.
11 changes: 2 additions & 9 deletions ext/curl/interface.c
Expand Up @@ -1952,8 +1952,6 @@ PHP_FUNCTION(curl_init)
ch->handlers->read->method = PHP_CURL_DIRECT;
ch->handlers->write_header->method = PHP_CURL_IGNORE;

ch->uses = 0;

MAKE_STD_ZVAL(clone);
ch->clone = clone;

Expand Down Expand Up @@ -1995,8 +1993,7 @@ PHP_FUNCTION(curl_copy_handle)
TSRMLS_SET_CTX(dupch->thread_ctx);

dupch->cp = cp;
dupch->uses = 0;
ch->uses++;
zend_list_addref(Z_LVAL_P(zid));
if (ch->handlers->write->stream) {
Z_ADDREF_P(ch->handlers->write->stream);
}
Expand Down Expand Up @@ -3210,11 +3207,7 @@ PHP_FUNCTION(curl_close)
return;
}

if (ch->uses) {
ch->uses--;
} else {
zend_list_delete(Z_LVAL_P(zid));
}
zend_list_delete(Z_LVAL_P(zid));
}
/* }}} */

Expand Down
13 changes: 4 additions & 9 deletions ext/curl/multi.c
Expand Up @@ -86,7 +86,6 @@ PHP_FUNCTION(curl_multi_add_handle)
ZEND_FETCH_RESOURCE(ch, php_curl *, &z_ch, -1, le_curl_name, le_curl);

_php_curl_cleanup_handle(ch);
ch->uses++;

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

if (ch->uses) {
ch->uses--;
} else {
zend_list_delete(Z_LVAL_P(z_ch));
}
zend_list_delete(Z_LVAL_P(z_ch));
}
/* }}} */

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

--ch->uses;


RETVAL_LONG((long) curl_multi_remove_handle(mh->multi, ch->cp));
zend_llist_del_element( &mh->easyh, &z_ch,
(int (*)(void *, void *)) curl_compare_resources );

RETURN_LONG((long) curl_multi_remove_handle(mh->multi, ch->cp));

}
/* }}} */

Expand Down
1 change: 0 additions & 1 deletion ext/curl/php_curl.h
Expand Up @@ -169,7 +169,6 @@ typedef struct {
CURL *cp;
php_curl_handlers *handlers;
long id;
unsigned int uses;
zend_bool in_callback;
zval *clone;
} php_curl;
Expand Down

0 comments on commit f85e595

Please sign in to comment.