From 3f4ef483a2706262e5a82051ae7f90b23d96de6c Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Wed, 14 Jan 2015 14:55:54 +0100 Subject: [PATCH 1/9] Fix double free in rpc plugin Reported by Coverity as CID #1264357 --- plugins/rpc/rpc_plugin.c | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/rpc/rpc_plugin.c b/plugins/rpc/rpc_plugin.c index b8a14a21..d3996678 100644 --- a/plugins/rpc/rpc_plugin.c +++ b/plugins/rpc/rpc_plugin.c @@ -455,7 +455,6 @@ static int uwsgi_routing_func_rpc_var(struct wsgi_request *wsgi_req, struct uwsg if (size == 0) goto end; if (!uwsgi_req_append(wsgi_req, ur->data4, ur->data4_len, response, size)) { - free(response); goto end; } ret = UWSGI_ROUTE_NEXT; From 9f060d05f6ec8907c0051bbe148ae3f3f97bc57f Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Wed, 14 Jan 2015 14:58:39 +0100 Subject: [PATCH 2/9] router_redis: fix memory leak Reported by Coverity as CID #1264356 --- plugins/router_redis/router_redis.c | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/router_redis/router_redis.c b/plugins/router_redis/router_redis.c index 52890893..7f123244 100644 --- a/plugins/router_redis/router_redis.c +++ b/plugins/router_redis/router_redis.c @@ -310,6 +310,7 @@ static int uwsgi_router_redis(struct uwsgi_route *ur, char *args) { if (!urrc->key || !urrc->addr) { uwsgi_log("invalid route syntax: you need to specify a redis address and key pattern\n"); + free(urrc); return -1; } From 61d8ce0a87e5feccb7d18ce1b38e6fe423a6236a Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Wed, 14 Jan 2015 15:12:11 +0100 Subject: [PATCH 3/9] router_static: fix memory leak Reported by Coverity as CID #1264355 --- plugins/router_static/router_static.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/router_static/router_static.c b/plugins/router_static/router_static.c index 232b37e9..6514d7b9 100644 --- a/plugins/router_static/router_static.c +++ b/plugins/router_static/router_static.c @@ -67,7 +67,10 @@ int uwsgi_routing_func_file(struct wsgi_request *wsgi_req, struct uwsgi_route *u // static file - don't update avg_rt after request wsgi_req->do_not_account_avg_rt = 1; - if (urfc->no_headers) goto send; + if (urfc->no_headers) { + uwsgi_buffer_destroy(ub_s); + goto send; + } if (uwsgi_response_prepare_headers(wsgi_req, ub_s->buf, ub_s->pos)) { uwsgi_buffer_destroy(ub_s); From 5432b7930c9d324a6d8cec36655baa8fdd7e56fd Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Wed, 14 Jan 2015 15:14:25 +0100 Subject: [PATCH 4/9] router_redis: fix memory leak Reported by Coverity as CID #1264354 --- plugins/router_redis/router_redis.c | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/router_redis/router_redis.c b/plugins/router_redis/router_redis.c index 7f123244..fdf009d6 100644 --- a/plugins/router_redis/router_redis.c +++ b/plugins/router_redis/router_redis.c @@ -345,6 +345,7 @@ static int uwsgi_router_redis_store(struct uwsgi_route *ur, char *args) { if (!urrc->key || !urrc->addr) { uwsgi_log("invalid redisstore route syntax: you need to specify an address and a key\n"); + free(urrc); return -1; } From 0ac92e1ad1c0266680508ff675a5672c8ba50619 Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Wed, 14 Jan 2015 15:15:43 +0100 Subject: [PATCH 5/9] router_static: fix memory leak Reported by Coverity as CID #1264353 --- plugins/router_static/router_static.c | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/router_static/router_static.c b/plugins/router_static/router_static.c index 6514d7b9..7ea438ad 100644 --- a/plugins/router_static/router_static.c +++ b/plugins/router_static/router_static.c @@ -291,6 +291,7 @@ static int uwsgi_router_file(struct uwsgi_route *ur, char *args) { if (!urfc->filename) { uwsgi_log("you have to specifify a filename for the \"file\" router\n"); + free(urfc); return -1; } From cd115371b03138afaa8d4bfe6c72f2ed0ae8abdb Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Wed, 14 Jan 2015 15:17:28 +0100 Subject: [PATCH 6/9] router_static: fix a couple of memory leaks Reported by Coverity as CID #1264352, #1264351 --- plugins/router_static/router_static.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/plugins/router_static/router_static.c b/plugins/router_static/router_static.c index 7ea438ad..14c5d8e2 100644 --- a/plugins/router_static/router_static.c +++ b/plugins/router_static/router_static.c @@ -141,7 +141,10 @@ int uwsgi_routing_func_sendfile(struct wsgi_request *wsgi_req, struct uwsgi_rout // static file - don't update avg_rt after request wsgi_req->do_not_account_avg_rt = 1; - if (urfc->no_headers) goto send; + if (urfc->no_headers) { + uwsgi_buffer_destroy(ub_s); + goto send; + } if (uwsgi_response_prepare_headers(wsgi_req, ub_s->buf, ub_s->pos)) { uwsgi_buffer_destroy(ub_s); @@ -211,7 +214,10 @@ int uwsgi_routing_func_fastfile(struct wsgi_request *wsgi_req, struct uwsgi_rout // static file - don't update avg_rt after request wsgi_req->do_not_account_avg_rt = 1; - if (urfc->no_headers) goto send; + if (urfc->no_headers) { + uwsgi_buffer_destroy(ub_s); + goto send; + } if (uwsgi_response_prepare_headers(wsgi_req, ub_s->buf, ub_s->pos)) { uwsgi_buffer_destroy(ub_s); From 4b9627950dd0bd5225697861f40cc08bc6424b33 Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Wed, 14 Jan 2015 15:21:39 +0100 Subject: [PATCH 7/9] router_memcached: fix a few memory leaks Reported by Coverity as CID #1264350, #1264349 --- plugins/router_memcached/router_memcached.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/router_memcached/router_memcached.c b/plugins/router_memcached/router_memcached.c index 9b0d2142..b4bbb97d 100644 --- a/plugins/router_memcached/router_memcached.c +++ b/plugins/router_memcached/router_memcached.c @@ -312,6 +312,7 @@ static int uwsgi_router_memcached(struct uwsgi_route *ur, char *args) { if (!urmc->key || !urmc->addr) { uwsgi_log("invalid route syntax: you need to specify a memcached address and key pattern\n"); + free(urmc); return -1; } @@ -346,6 +347,7 @@ static int uwsgi_router_memcached_store(struct uwsgi_route *ur, char *args) { if (!urmc->key || !urmc->addr) { uwsgi_log("invalid memcachedstore route syntax: you need to specify an address and a key\n"); + free(urmc); return -1; } From 2cd5d51ca9f650ad29c0c73e3020e6bceb84f843 Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Wed, 14 Jan 2015 15:27:25 +0100 Subject: [PATCH 8/9] core/hooks: fix a couple of leaks Reported by Coverity as CID #1264345, #1264347 --- core/hooks.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/hooks.c b/core/hooks.c index a9112a9d..0e6c5365 100644 --- a/core/hooks.c +++ b/core/hooks.c @@ -738,7 +738,8 @@ void uwsgi_hooks_setns_run(struct uwsgi_string_list *l, pid_t pid, uid_t uid, gi uwsgi_error("uwsgi_hooks_setns_run()/setns()"); exit(1); } - + close(fd); + free(procfile); } if (setenv("UWSGI_VASSAL_PID", pidstr, 1)) { From 4998a10578a56a4cc1a552c9a7ca69b6819151dd Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Wed, 14 Jan 2015 15:32:48 +0100 Subject: [PATCH 9/9] subscription: fix memory leak Reported by CID as #1264346 --- core/subscription.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/core/subscription.c b/core/subscription.c index a3765ef0..6bd03f28 100644 --- a/core/subscription.c +++ b/core/subscription.c @@ -931,6 +931,7 @@ void uwsgi_subscribe2(char *arg, uint8_t cmd) { char *s2_proto = NULL; char *s2_algo = NULL; char *s2_backup = NULL; + struct uwsgi_buffer *ub = NULL; if (uwsgi_kvlist_parse(arg, strlen(arg), ',', '=', "server", &s2_server, @@ -998,7 +999,7 @@ void uwsgi_subscribe2(char *arg, uint8_t cmd) { s2_addr = uwsgi_str(uwsgi.sockets->name); } - struct uwsgi_buffer *ub = uwsgi_buffer_new(uwsgi.page_size); + ub = uwsgi_buffer_new(uwsgi.page_size); if (!ub) goto end; // leave space for the header ub->pos = 4; @@ -1058,9 +1059,10 @@ void uwsgi_subscribe2(char *arg, uint8_t cmd) { send_subscription(-1, s2_server, ub->buf, ub->pos); - uwsgi_buffer_destroy(ub); - end: + if (ub) + uwsgi_buffer_destroy(ub); + if (s2_server) free(s2_server); if (s2_key)