Skip to content

Commit

Permalink
Avoid multipy allocating of request env
Browse files Browse the repository at this point in the history
  • Loading branch information
laruence committed May 23, 2015
1 parent 86de98c commit f20118a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
9 changes: 7 additions & 2 deletions main/fastcgi.c
Original file line number Diff line number Diff line change
Expand Up @@ -794,10 +794,17 @@ fcgi_request *fcgi_init_request(fcgi_request *req, int listen_socket)
#ifdef _WIN32
req->tcp = !GetNamedPipeInfo((HANDLE)_get_osfhandle(req->listen_socket), NULL, NULL, NULL, NULL);
#endif
fcgi_hash_init(&req->env);

return req;
}

void fcgi_destroy_request(fcgi_request *req) {
if (req->env.buckets) {
fcgi_hash_destroy(&req->env);
}
}

static inline ssize_t safe_write(fcgi_request *req, const void *buf, size_t count)
{
int ret;
Expand Down Expand Up @@ -935,7 +942,6 @@ static int fcgi_read_request(fcgi_request *req)
req->in_len = 0;
req->out_hdr = NULL;
req->out_pos = req->out_buf;
fcgi_hash_init(&req->env);
req->has_env = 1;

if (safe_read(req, &hdr, sizeof(fcgi_header)) != sizeof(fcgi_header) ||
Expand Down Expand Up @@ -1144,7 +1150,6 @@ void fcgi_close(fcgi_request *req, int force, int destroy)
{
if (destroy && req->has_env) {
fcgi_hash_clean(&req->env);
fcgi_hash_destroy(&req->env);
req->has_env = 0;
}

Expand Down
1 change: 1 addition & 0 deletions main/fastcgi.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ int fcgi_in_shutdown(void);
void fcgi_terminate(void);
int fcgi_listen(const char *path, int backlog);
fcgi_request* fcgi_init_request(fcgi_request *request, int listen_socket);
void fcgi_destroy_request(fcgi_request *req);
void fcgi_set_allowed_clients(char *ip);
int fcgi_accept_request(fcgi_request *req);
int fcgi_finish_request(fcgi_request *req, int force_close);
Expand Down
2 changes: 2 additions & 0 deletions sapi/cgi/cgi_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2101,6 +2101,7 @@ consult the installation file that came with this distribution, or visit \n\
break;
case 'h':
case '?':
fcgi_destroy_request(&request);
fcgi_shutdown();
no_headers = 1;
SG(headers_sent) = 1;
Expand Down Expand Up @@ -2532,6 +2533,7 @@ consult the installation file that came with this distribution, or visit \n\
}
/* end of fastcgi loop */
}
fcgi_destroy_request(&request);
fcgi_shutdown();

if (cgi_sapi_module.php_ini_path_override) {
Expand Down
1 change: 1 addition & 0 deletions sapi/fpm/fpm/fpm_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1972,6 +1972,7 @@ consult the installation file that came with this distribution, or visit \n\
}
/* end of fastcgi loop */
}
fcgi_destroy_request(&request);
fcgi_shutdown();

if (cgi_sapi_module.php_ini_path_override) {
Expand Down

0 comments on commit f20118a

Please sign in to comment.