Skip to content
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
8 changes: 5 additions & 3 deletions src/request.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ static void signalforge_request_free_object(zend_object *object)
if (!Z_ISUNDEF(intern->zv_method_override_post)) zval_ptr_dtor(&intern->zv_method_override_post);
if (!Z_ISUNDEF(intern->zv_uri)) zval_ptr_dtor(&intern->zv_uri);
if (!Z_ISUNDEF(intern->zv_query_string)) zval_ptr_dtor(&intern->zv_query_string);

/* Free owned HashTables */
if (intern->ht_headers) {
zend_hash_destroy(intern->ht_headers);
Expand Down Expand Up @@ -977,7 +977,7 @@ PHP_METHOD(Signalforge_Http_Request, getHeaders)
{
signalforge_request_object *intern = Z_SIGNALFORGE_REQUEST_P(ZEND_THIS);
ZEND_PARSE_PARAMETERS_NONE();

if (intern->ht_headers) {
/* Convert HashTable to array, ensuring values are arrays */
array_init(return_value);
Expand All @@ -993,7 +993,9 @@ PHP_METHOD(Signalforge_Http_Request, getHeaders)
Z_TRY_ADDREF_P(val);
add_next_index_zval(&header_array, val);
}
zend_hash_add(Z_ARRVAL_P(return_value), key, &header_array);
/* Use add_assoc_zval_ex to create fresh key rather than reusing source key.
* This avoids reference counting issues when source HashTable is destroyed. */
add_assoc_zval_ex(return_value, ZSTR_VAL(key), ZSTR_LEN(key), &header_array);
}
} ZEND_HASH_FOREACH_END();
} else {
Expand Down
4 changes: 3 additions & 1 deletion src/response.c
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,9 @@ PHP_METHOD(Signalforge_Http_Response, getHeaders)
Z_TRY_ADDREF_P(val);
add_next_index_zval(&header_array, val);
}
zend_hash_add(Z_ARRVAL_P(return_value), key, &header_array);
/* Use add_assoc_zval_ex to create fresh key rather than reusing source key.
* This avoids reference counting issues when source HashTable is destroyed. */
add_assoc_zval_ex(return_value, ZSTR_VAL(key), ZSTR_LEN(key), &header_array);
}
} ZEND_HASH_FOREACH_END();
} else {
Expand Down