Commit e3c95265 authored by Tatsuhiro Tsujikawa's avatar Tatsuhiro Tsujikawa

nghttpd: Fix leak when server failed to listen to given port

parent 46d7c30c
......@@ -1671,7 +1671,7 @@ int start_listen(HttpServer *sv, struct ev_loop *loop, Sessions *sessions,
bool ok = false;
const char *addr = nullptr;
auto acceptor = std::make_shared<AcceptHandler>(sv, sessions, config);
std::shared_ptr<AcceptHandler> acceptor;
auto service = util::utos(config->port);
addrinfo hints{};
......@@ -1715,6 +1715,9 @@ int start_listen(HttpServer *sv, struct ev_loop *loop, Sessions *sessions,
}
#endif // IPV6_V6ONLY
if (bind(fd, rp->ai_addr, rp->ai_addrlen) == 0 && listen(fd, 1000) == 0) {
if (!acceptor) {
acceptor = std::make_shared<AcceptHandler>(sv, sessions, config);
}
new ListenEventHandler(sessions, fd, acceptor);
if (config->verbose) {
......@@ -1870,6 +1873,9 @@ int HttpServer::run() {
Sessions sessions(this, loop, config_, ssl_ctx);
if (start_listen(this, loop, &sessions, config_) != 0) {
std::cerr << "Could not listen" << std::endl;
if (ssl_ctx) {
SSL_CTX_free(ssl_ctx);
}
return -1;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment