Skip to content

Commit 03e03f7

Browse files
committed
fix memory leak.
1 parent 46ba3a3 commit 03e03f7

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

examples/http/post.data

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dd=wwwwww&ddd=eee&3412=3234&hello=world%2C+i+am+rango%2C+thank+you.+no+body

swoole_http.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ static int multipart_body_on_data_end(multipart_parser* p)
767767
zend_update_property(swoole_http_request_class_entry_ptr, client->request.zrequest_object, ZEND_STRL("post"), zpost TSRMLS_CC);
768768
}
769769

770-
sw_add_assoc_stringl_ex(zpost, client->current_form_data_name, client->current_form_data_name_len + 1,
770+
sw_add_assoc_stringl_ex(zpost, client->current_form_data_name, client->current_form_data_name_len + 1,
771771
swoole_http_form_data_buffer->str, swoole_http_form_data_buffer->length, 1);
772772

773773
efree(client->current_form_data_name);
@@ -826,14 +826,14 @@ static int http_request_on_body(php_http_parser *parser, const char *at, size_t
826826

827827
if (SwooleG.serv->http_parse_post && client->request.post_form_urlencoded)
828828
{
829-
zval *post;
830-
SW_MAKE_STD_ZVAL(post);
831-
array_init(post);
829+
zval *zpost;
830+
http_alloc_zval(client, request, zpost);
831+
array_init(zpost);
832832

833833
body = estrndup(at, length);
834-
zend_update_property(swoole_http_request_class_entry_ptr, client->request.zrequest_object, ZEND_STRL("post"), post TSRMLS_CC);
835-
sapi_module.treat_data(PARSE_STRING, body, post TSRMLS_CC);
836-
http_merge_php_global(post, client->request.zrequest_object, HTTP_GLOBAL_POST);
834+
zend_update_property(swoole_http_request_class_entry_ptr, client->request.zrequest_object, ZEND_STRL("post"), zpost TSRMLS_CC);
835+
sapi_module.treat_data(PARSE_STRING, body, zpost TSRMLS_CC);
836+
http_merge_php_global(zpost, client->request.zrequest_object, HTTP_GLOBAL_POST);
837837
}
838838
else if (client->mt_parser != NULL)
839839
{
@@ -1195,6 +1195,11 @@ void swoole_http_request_free(swoole_http_client *client TSRMLS_DC)
11951195
{
11961196
sw_zval_ptr_dtor(&req->zcookie);
11971197
}
1198+
//request data
1199+
if (req->zdata)
1200+
{
1201+
sw_zval_ptr_dtor(&req->zdata);
1202+
}
11981203
//upload files
11991204
if (req->zfiles)
12001205
{
@@ -1213,11 +1218,11 @@ void swoole_http_request_free(swoole_http_client *client TSRMLS_DC)
12131218
continue;
12141219
}
12151220
zval *file_path;
1216-
if (sw_zend_hash_find(Z_ARRVAL_P(value), ZEND_STRS("tmp_name"), (void **) &file_path)
1217-
== SUCCESS)
1221+
if (sw_zend_hash_find(Z_ARRVAL_P(value), ZEND_STRS("tmp_name"), (void **) &file_path) == SUCCESS)
12181222
{
12191223
unlink(Z_STRVAL_P(file_path));
1220-
} sw_zval_ptr_dtor(&value);
1224+
}
1225+
sw_zval_ptr_dtor(&value);
12211226
}
12221227
SW_HASHTABLE_FOREACH_END();
12231228

@@ -1254,11 +1259,6 @@ void swoole_http_request_free(swoole_http_client *client TSRMLS_DC)
12541259
sw_zval_ptr_dtor(&client->response.zresponse_object);
12551260
client->response.zresponse_object = NULL;
12561261
}
1257-
//request data
1258-
if (req->zdata)
1259-
{
1260-
sw_zval_ptr_dtor(&req->zdata);
1261-
}
12621262

12631263
client->end = 1;
12641264
client->send_header = 0;

0 commit comments

Comments
 (0)