Fri, 13 Jan 2017 09:53:55 +0100
fixes memory leaks in request_stat_path and send_cgi
--- a/src/server/daemon/config.c Sat Dec 31 18:05:40 2016 +0100 +++ b/src/server/daemon/config.c Fri Jan 13 09:53:55 2017 +0100 @@ -292,7 +292,7 @@ int cfg_handle_runtime(ServerConfiguration *cfg, ServerConfigObject *obj) { sstr_t user = cfg_directivelist_get_str(obj->directives, sstr("User")); if(user.ptr) { - //cfg->user = sstrdup_pool(cfg->pool, user); + cfg->user = sstrdup_pool(cfg->pool, user); } sstr_t tmp = cfg_directivelist_get_str(obj->directives, sstr("Temp")); if(tmp.ptr) {
--- a/src/server/daemon/httplistener.c Sat Dec 31 18:05:40 2016 +0100 +++ b/src/server/daemon/httplistener.c Fri Jan 13 09:53:55 2017 +0100 @@ -387,7 +387,7 @@ perror("Error: acceptor_thread: accept"); continue; } - + // check listener HttpListener *ls = listener; int acceptor_exit = 0;
--- a/src/server/daemon/request.c Sat Dec 31 18:05:40 2016 +0100 +++ b/src/server/daemon/request.c Fri Jan 13 09:53:55 2017 +0100 @@ -119,6 +119,7 @@ // TODO: use pool struct stat *s = malloc(sizeof(struct stat)); if(stat(path, s)) { + free(s); return NULL; } // TODO: statpath and staterror
--- a/src/server/safs/cgi.c Sat Dec 31 18:05:40 2016 +0100 +++ b/src/server/safs/cgi.c Fri Jan 13 09:53:55 2017 +0100 @@ -83,10 +83,13 @@ CGIProcess cgip; int ret = cgi_start(&cgip, path, argv, env); if(ret != REQ_PROCEED) { + util_env_free(env); + cgi_free_argv(argv); return ret; } util_env_free(env); + cgi_free_argv(argv); char buf[4096]; // I/O buffer ssize_t r; @@ -246,6 +249,7 @@ * -1: error */ static int parse_lines(CGIResponseParser *parser, char *buf, size_t len, int *pos) { + UcxAllocator a = util_pool_allocator(parser->sn->pool); sstr_t name; sstr_t value; WSBool space = TRUE; @@ -270,7 +274,7 @@ } value = sstrn(buf + value_begin, i - value_begin); - name = sstrlower(sstrtrim(name)); + name = sstrlower_a(&a, sstrtrim(name)); value = sstrtrim(value); if(name.length == 0 || value.length == 0) {
--- a/src/server/safs/cgiutils.c Sat Dec 31 18:05:40 2016 +0100 +++ b/src/server/safs/cgiutils.c Fri Jan 13 09:53:55 2017 +0100 @@ -155,6 +155,15 @@ return argv; } +void cgi_free_argv(char **args) { + int i = 0; + while(args[i] != NULL) { + free(args[i]); + i++; + } + free(args); +} + //---------------------------------------------------------------------------- // cgi_get_request_uri //----------------------------------------------------------------------------
--- a/src/server/safs/cgiutils.h Sat Dec 31 18:05:40 2016 +0100 +++ b/src/server/safs/cgiutils.h Fri Jan 13 09:53:55 2017 +0100 @@ -37,6 +37,7 @@ int cgi_parse_query(char **argv, int n, char *q); char **cgi_create_argv(const char *program, const char *script, const char *query); +void cgi_free_argv(char **args); char* cgi_get_request_uri(Request *req); char** cgi_specific_vars(Session *sn, Request *rq, const char *args, char** env, int scriptVars);
--- a/src/server/safs/pathcheck.c Sat Dec 31 18:05:40 2016 +0100 +++ b/src/server/safs/pathcheck.c Fri Jan 13 09:53:55 2017 +0100 @@ -79,7 +79,9 @@ for(int i=0;i<n;i++) { sstr_t right = rights[i]; access_mask = access_mask | accstr2int(right); + free(right.ptr); } + free(rights); rq->aclreqaccess = access_mask;