From bcba95129101691179da580697e87d19aeb3bfe4 Mon Sep 17 00:00:00 2001 From: Anastasia Filimonova Date: Wed, 6 May 2026 08:42:10 +0300 Subject: [PATCH 1/2] Fix(plugins): close plugin_handle on dlsym() failure Plugin handle acquired via dlopen() is not closed if both dlsym() calls fail. Add dlclose() to the cleanup block before returning. Fixes handle leak found by Svace static analyzer --- core/plugins.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/plugins.c b/core/plugins.c index fad2c3fbe0..b3643bdc5a 100644 --- a/core/plugins.c +++ b/core/plugins.c @@ -270,6 +270,9 @@ void *uwsgi_load_plugin(int modifier, char *plugin, char *has_option) { free(plugin_name); if (plugin_filename) free(plugin_filename); + if (plugin_handle && dlclose(plugin_handle)) { + uwsgi_error("dlclose()"); + } return NULL; } From 608adf727b3f1460656bc78812d16e27e516ef8d Mon Sep 17 00:00:00 2001 From: Anastasia Filimonova Date: Wed, 6 May 2026 08:44:05 +0300 Subject: [PATCH 2/2] Fix(socket): close serverfd on several error paths after uwsgi_nuclear_blast() Socket descriptor serverfd may leak if uwsgi_nuclear_blast() returns (e.g., when running as Emperor) instead of terminating the process. Close the descriptor in this case. Fixes handle leak found by Svace static analyzer --- core/socket.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/socket.c b/core/socket.c index 932292294e..57919141b3 100644 --- a/core/socket.c +++ b/core/socket.c @@ -94,6 +94,7 @@ static int create_server_socket(int domain, int type) { if (setsockopt(serverfd, SOL_SOCKET, SO_REUSEADDR, (const void *) &reuse, sizeof(int)) < 0) { uwsgi_error("SO_REUSEADDR setsockopt()"); uwsgi_nuclear_blast(); + close(serverfd); return -1; } } @@ -104,6 +105,7 @@ static int create_server_socket(int domain, int type) { if (setsockopt(serverfd, SOL_SOCKET, SO_SNDBUF, &sndbuf, sizeof(socklen_t)) < 0) { uwsgi_error("SO_SNDBUF setsockopt()"); uwsgi_nuclear_blast(); + close(serverfd); return -1; } else { @@ -116,6 +118,7 @@ static int create_server_socket(int domain, int type) { if (setsockopt(serverfd, SOL_SOCKET, SO_RCVBUF, &rcvbuf, sizeof(socklen_t)) < 0) { uwsgi_error("SO_RCVBUF setsockopt()"); uwsgi_nuclear_blast(); + close(serverfd); return -1; } else { @@ -128,6 +131,7 @@ static int create_server_socket(int domain, int type) { if (somaxconn > 0 && uwsgi.listen_queue > somaxconn) { uwsgi_log("Listen queue size is greater than the system max net.core.somaxconn (%li).\n", somaxconn); uwsgi_nuclear_blast(); + close(serverfd); return -1; } #endif