curl: Remove unnecessary dynamic allocation for HashTable in _php_curl_free (#16297)

Given that the lifecycle of the `slist` HashTable exactly matches the lifecycle
of the `_php_curl_free` struct, we might as well embed the HashTable directly
and avoid a pointer indirection.
This commit is contained in:
Tim Düsterhus 2024-10-08 15:07:32 +02:00 committed by GitHub
parent 4b97e7bf02
commit 35a681d717
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 5 additions and 8 deletions

View file

@ -89,7 +89,7 @@ struct _php_curl_send_headers {
struct _php_curl_free { struct _php_curl_free {
zend_llist post; zend_llist post;
zend_llist stream; zend_llist stream;
HashTable *slist; HashTable slist;
}; };
typedef struct { typedef struct {

View file

@ -1143,8 +1143,7 @@ void init_curl_handle(php_curl *ch)
zend_llist_init(&ch->to_free->post, sizeof(struct HttpPost *), (llist_dtor_func_t)curl_free_post, 0); zend_llist_init(&ch->to_free->post, sizeof(struct HttpPost *), (llist_dtor_func_t)curl_free_post, 0);
zend_llist_init(&ch->to_free->stream, sizeof(struct mime_data_cb_arg *), (llist_dtor_func_t)curl_free_cb_arg, 0); zend_llist_init(&ch->to_free->stream, sizeof(struct mime_data_cb_arg *), (llist_dtor_func_t)curl_free_cb_arg, 0);
ch->to_free->slist = emalloc(sizeof(HashTable)); zend_hash_init(&ch->to_free->slist, 4, NULL, curl_free_slist, 0);
zend_hash_init(ch->to_free->slist, 4, NULL, curl_free_slist, 0);
ZVAL_UNDEF(&ch->postfields); ZVAL_UNDEF(&ch->postfields);
} }
@ -1312,7 +1311,6 @@ void _php_setup_easy_copy_handlers(php_curl *ch, php_curl *source)
ZVAL_COPY(&ch->private_data, &source->private_data); ZVAL_COPY(&ch->private_data, &source->private_data);
efree(ch->to_free->slist);
efree(ch->to_free); efree(ch->to_free);
ch->to_free = source->to_free; ch->to_free = source->to_free;
efree(ch->clone); efree(ch->clone);
@ -2160,9 +2158,9 @@ static zend_result _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue
if (slist) { if (slist) {
if ((*ch->clone) == 1) { if ((*ch->clone) == 1) {
zend_hash_index_update_ptr(ch->to_free->slist, option, slist); zend_hash_index_update_ptr(&ch->to_free->slist, option, slist);
} else { } else {
zend_hash_next_index_insert_ptr(ch->to_free->slist, slist); zend_hash_next_index_insert_ptr(&ch->to_free->slist, slist);
} }
} }
@ -2803,8 +2801,7 @@ static void curl_free_obj(zend_object *object)
zend_llist_clean(&ch->to_free->post); zend_llist_clean(&ch->to_free->post);
zend_llist_clean(&ch->to_free->stream); zend_llist_clean(&ch->to_free->stream);
zend_hash_destroy(ch->to_free->slist); zend_hash_destroy(&ch->to_free->slist);
efree(ch->to_free->slist);
efree(ch->to_free); efree(ch->to_free);
efree(ch->clone); efree(ch->clone);
} }