listen_loop(): Delay the call to ssl_release()
authorFabian Keil <fk@fabiankeil.de>
Fri, 22 Jan 2021 12:01:35 +0000 (13:01 +0100)
committerFabian Keil <fk@fabiankeil.de>
Fri, 22 Jan 2021 13:26:26 +0000 (14:26 +0100)
... and only release the TLS backend resources if there
are no active connections left.

Prevents crashes when exiting "gracefully" at the wrong time.

jcc.c

diff --git a/jcc.c b/jcc.c
index ab4956f..310fb1e 100644 (file)
--- a/jcc.c
+++ b/jcc.c
@@ -6183,11 +6183,6 @@ static void listen_loop(void)
 
    /* NOTREACHED unless FEATURE_GRACEFUL_TERMINATION is defined */
 
 
    /* NOTREACHED unless FEATURE_GRACEFUL_TERMINATION is defined */
 
-#ifdef FEATURE_HTTPS_INSPECTION
-   /* Clean up.  Aim: free all memory (no leaks) */
-   ssl_release();
-#endif
-
 #ifdef FEATURE_GRACEFUL_TERMINATION
 
    log_error(LOG_LEVEL_INFO, "Graceful termination requested.");
 #ifdef FEATURE_GRACEFUL_TERMINATION
 
    log_error(LOG_LEVEL_INFO, "Graceful termination requested.");
@@ -6220,6 +6215,17 @@ static void listen_loop(void)
    freez(basedir);
 #endif
 
    freez(basedir);
 #endif
 
+#ifdef FEATURE_HTTPS_INSPECTION
+   /*
+    * Only release TLS backed resources if there
+    * are no active connections left.
+    */
+   if (clients->next == NULL)
+   {
+      ssl_release();
+   }
+#endif
+
    log_error(LOG_LEVEL_INFO, "Exiting gracefully.");
 
 #if defined(_WIN32) && !defined(_WIN_CONSOLE)
    log_error(LOG_LEVEL_INFO, "Exiting gracefully.");
 
 #if defined(_WIN32) && !defined(_WIN_CONSOLE)