]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Clean up the Lua objects before exiting 13667/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 26 Dec 2023 13:07:05 +0000 (14:07 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 26 Dec 2023 13:09:25 +0000 (14:09 +0100)
When code coverage is enabled, we try to call `exit()` instead of our
usual use of `_exit()` to get more accurate coverage. It does however
trigger a race condition between the destruction of Lua objects and
the Lua context(s) they belong to, so we try to explicitly clean up
the objects before calling `exit()`.

pdns/dnsdist.cc

index 3df62e18e2d6e784fd55f9d3a914fa44d48cde63..54ba9777d0d79670f1dabd307c4605333dffffb7 100644 (file)
@@ -2525,8 +2525,8 @@ static void usage()
 #ifdef COVERAGE
 static void cleanupLuaObjects()
 {
-  /* when our coverage mode is enabled, we need to make
-     that the Lua objects destroyed before the Lua contexts. */
+  /* when our coverage mode is enabled, we need to make sure
+     that the Lua objects are destroyed before the Lua contexts. */
   g_ruleactions.setState({});
   g_respruleactions.setState({});
   g_cachehitrespruleactions.setState({});
@@ -3215,6 +3215,7 @@ int main(int argc, char** argv)
       errlog("Fatal pdns error: %s", ae.reason);
     }
 #ifdef COVERAGE
+    cleanupLuaObjects();
     exit(EXIT_FAILURE);
 #else
     _exit(EXIT_FAILURE);
@@ -3224,6 +3225,7 @@ int main(int argc, char** argv)
   {
     errlog("Fatal error: %s", e.what());
 #ifdef COVERAGE
+    cleanupLuaObjects();
     exit(EXIT_FAILURE);
 #else
     _exit(EXIT_FAILURE);
@@ -3233,6 +3235,7 @@ int main(int argc, char** argv)
   {
     errlog("Fatal pdns error: %s", ae.reason);
 #ifdef COVERAGE
+    cleanupLuaObjects();
     exit(EXIT_FAILURE);
 #else
     _exit(EXIT_FAILURE);