Skip to content

Commit f20118a

Browse files
committed
Avoid multipy allocating of request env
1 parent 86de98c commit f20118a

File tree

4 files changed

+11
-2
lines changed

4 files changed

+11
-2
lines changed

main/fastcgi.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -794,10 +794,17 @@ fcgi_request *fcgi_init_request(fcgi_request *req, int listen_socket)
794794
#ifdef _WIN32
795795
req->tcp = !GetNamedPipeInfo((HANDLE)_get_osfhandle(req->listen_socket), NULL, NULL, NULL, NULL);
796796
#endif
797+
fcgi_hash_init(&req->env);
797798

798799
return req;
799800
}
800801

802+
void fcgi_destroy_request(fcgi_request *req) {
803+
if (req->env.buckets) {
804+
fcgi_hash_destroy(&req->env);
805+
}
806+
}
807+
801808
static inline ssize_t safe_write(fcgi_request *req, const void *buf, size_t count)
802809
{
803810
int ret;
@@ -935,7 +942,6 @@ static int fcgi_read_request(fcgi_request *req)
935942
req->in_len = 0;
936943
req->out_hdr = NULL;
937944
req->out_pos = req->out_buf;
938-
fcgi_hash_init(&req->env);
939945
req->has_env = 1;
940946

941947
if (safe_read(req, &hdr, sizeof(fcgi_header)) != sizeof(fcgi_header) ||
@@ -1144,7 +1150,6 @@ void fcgi_close(fcgi_request *req, int force, int destroy)
11441150
{
11451151
if (destroy && req->has_env) {
11461152
fcgi_hash_clean(&req->env);
1147-
fcgi_hash_destroy(&req->env);
11481153
req->has_env = 0;
11491154
}
11501155

main/fastcgi.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ int fcgi_in_shutdown(void);
195195
void fcgi_terminate(void);
196196
int fcgi_listen(const char *path, int backlog);
197197
fcgi_request* fcgi_init_request(fcgi_request *request, int listen_socket);
198+
void fcgi_destroy_request(fcgi_request *req);
198199
void fcgi_set_allowed_clients(char *ip);
199200
int fcgi_accept_request(fcgi_request *req);
200201
int fcgi_finish_request(fcgi_request *req, int force_close);

sapi/cgi/cgi_main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2101,6 +2101,7 @@ consult the installation file that came with this distribution, or visit \n\
21012101
break;
21022102
case 'h':
21032103
case '?':
2104+
fcgi_destroy_request(&request);
21042105
fcgi_shutdown();
21052106
no_headers = 1;
21062107
SG(headers_sent) = 1;
@@ -2532,6 +2533,7 @@ consult the installation file that came with this distribution, or visit \n\
25322533
}
25332534
/* end of fastcgi loop */
25342535
}
2536+
fcgi_destroy_request(&request);
25352537
fcgi_shutdown();
25362538

25372539
if (cgi_sapi_module.php_ini_path_override) {

sapi/fpm/fpm/fpm_main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1972,6 +1972,7 @@ consult the installation file that came with this distribution, or visit \n\
19721972
}
19731973
/* end of fastcgi loop */
19741974
}
1975+
fcgi_destroy_request(&request);
19751976
fcgi_shutdown();
19761977

19771978
if (cgi_sapi_module.php_ini_path_override) {

0 commit comments

Comments
 (0)