Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ext/curl/curl_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ struct _php_curl_send_headers {
struct _php_curl_free {
zend_llist post;
zend_llist stream;
HashTable *slist;
HashTable slist;
};

typedef struct {
Expand Down
11 changes: 4 additions & 7 deletions ext/curl/interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -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->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);
}

Expand Down Expand Up @@ -1312,7 +1311,6 @@ void _php_setup_easy_copy_handlers(php_curl *ch, php_curl *source)

ZVAL_COPY(&ch->private_data, &source->private_data);

efree(ch->to_free->slist);
efree(ch->to_free);
ch->to_free = source->to_free;
efree(ch->clone);
Expand Down Expand Up @@ -2160,9 +2158,9 @@ static zend_result _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue

if (slist) {
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 {
zend_hash_next_index_insert_ptr(ch->to_free->slist, slist);
zend_hash_next_index_insert_ptr(&ch->to_free->slist, slist);
}
}

Expand Down Expand Up @@ -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->stream);

zend_hash_destroy(ch->to_free->slist);
efree(ch->to_free->slist);
zend_hash_destroy(&ch->to_free->slist);
efree(ch->to_free);
efree(ch->clone);
}
Expand Down