]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
nss: use 'atexit()' to cleanup
authorVictor Julien <vjulien@oisf.net>
Thu, 7 Apr 2022 12:44:26 +0000 (14:44 +0200)
committerVictor Julien <vjulien@oisf.net>
Thu, 7 Apr 2022 15:42:49 +0000 (17:42 +0200)
This avoids ASAN to report leaks in case of fatal errors in tests.

src/suricata.c

index 42adee2dacf1336e0d2c4b9e3a835bdbb496b056..818e36f522a718fa70d68ce21040cb60cc15f62f 100644 (file)
@@ -356,12 +356,6 @@ static void GlobalsDestroy(SCInstance *suri)
     TmqhCleanup();
     TmModuleRunDeInit();
     ParseSizeDeinit();
-#ifdef HAVE_NSS
-    if (NSS_IsInitialized()) {
-        NSS_Shutdown();
-        PR_Cleanup();
-    }
-#endif
 
 #ifdef HAVE_AF_PACKET
     AFPPeersListClean();
@@ -2469,6 +2463,16 @@ static void SetupUserMode(SCInstance *suri)
     }
 }
 
+#ifdef HAVE_NSS
+static void AtExitNSSShutdown(void)
+{
+    if (NSS_IsInitialized()) {
+        NSS_Shutdown();
+        PR_Cleanup();
+    }
+}
+#endif
+
 /**
  * This function is meant to contain code that needs
  * to be run once the configuration has been loaded.
@@ -2630,6 +2634,7 @@ int PostConfLoadedSetup(SCInstance *suri)
         /* init NSS for hashing */
         PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
         NSS_NoDB_Init(NULL);
+        atexit(AtExitNSSShutdown);
     }
 #endif