nghttpd: Fix leak when server failed to listen to given port
This commit is contained in:
parent
46d7c30c17
commit
e3c95265a4
|
@ -1671,7 +1671,7 @@ int start_listen(HttpServer *sv, struct ev_loop *loop, Sessions *sessions,
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
const char *addr = nullptr;
|
const char *addr = nullptr;
|
||||||
|
|
||||||
auto acceptor = std::make_shared<AcceptHandler>(sv, sessions, config);
|
std::shared_ptr<AcceptHandler> acceptor;
|
||||||
auto service = util::utos(config->port);
|
auto service = util::utos(config->port);
|
||||||
|
|
||||||
addrinfo hints{};
|
addrinfo hints{};
|
||||||
|
@ -1715,6 +1715,9 @@ int start_listen(HttpServer *sv, struct ev_loop *loop, Sessions *sessions,
|
||||||
}
|
}
|
||||||
#endif // IPV6_V6ONLY
|
#endif // IPV6_V6ONLY
|
||||||
if (bind(fd, rp->ai_addr, rp->ai_addrlen) == 0 && listen(fd, 1000) == 0) {
|
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);
|
new ListenEventHandler(sessions, fd, acceptor);
|
||||||
|
|
||||||
if (config->verbose) {
|
if (config->verbose) {
|
||||||
|
@ -1870,6 +1873,9 @@ int HttpServer::run() {
|
||||||
Sessions sessions(this, loop, config_, ssl_ctx);
|
Sessions sessions(this, loop, config_, ssl_ctx);
|
||||||
if (start_listen(this, loop, &sessions, config_) != 0) {
|
if (start_listen(this, loop, &sessions, config_) != 0) {
|
||||||
std::cerr << "Could not listen" << std::endl;
|
std::cerr << "Could not listen" << std::endl;
|
||||||
|
if (ssl_ctx) {
|
||||||
|
SSL_CTX_free(ssl_ctx);
|
||||||
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue