From 38219556b66e56a292f30c9f44ae162fde2f881c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Wed, 8 Aug 2018 21:02:33 +0300 Subject: [PATCH] Fix crash on failure to listen on port If a listener was created at runtime and at some point it fails (e.g. the port is already taken), the listener would be removed from the service. In 2.2, the removal of the listeners simply marked the listener as inactive. In 2.3, the functions were combined so that the listener is marked as inactive and removed from the workers. The fact that the listener had a NULL DCB at that point caused the crash. The correct thing to do is to not remove the listener from the service and to mark the listener as inactive in the close_port helper function. The listener will be freed once the service is destroyed. --- server/core/service.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/core/service.cc b/server/core/service.cc index 9c32009a7..b74722bf1 100644 --- a/server/core/service.cc +++ b/server/core/service.cc @@ -322,6 +322,8 @@ static inline void close_port(SERV_LISTENER *port) dcb_close(port->listener); port->listener = NULL; } + + listener_set_active(port, false); } /** @@ -555,7 +557,6 @@ bool serviceLaunchListener(Service *service, SERV_LISTENER *port) if (serviceStartPort(service, port) == 0) { /** Failed to start the listener */ - service_remove_listener(service, port->name); rval = false; }