]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
nts: close socket in helper process on exit
authorMiroslav Lichvar <mlichvar@redhat.com>
Thu, 28 Nov 2024 13:45:23 +0000 (14:45 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 28 Nov 2024 15:09:19 +0000 (16:09 +0100)
Close the socket used for receiving helper requests before exit to avoid
another valgrind error.

nts_ke_server.c

index 6fe28be77110295da7fb806f4641cba01964d95f..6dd6251f3a0ef97df8bbe624f4698d29c5e4ff2d 100644 (file)
@@ -702,7 +702,7 @@ key_timeout(void *arg)
 /* ================================================== */
 
 static void
-run_helper(uid_t uid, gid_t gid, int scfilter_level)
+run_helper(uid_t uid, gid_t gid, int scfilter_level, int sock_fd)
 {
   LOG_Severity log_severity;
 
@@ -729,10 +729,15 @@ run_helper(uid_t uid, gid_t gid, int scfilter_level)
   if (scfilter_level != 0)
     SYS_EnableSystemCallFilter(scfilter_level, SYS_NTSKE_HELPER);
 
+  SCH_AddFileHandler(sock_fd, SCH_FILE_INPUT, handle_helper_request, NULL);
+
   SCH_MainLoop();
 
   DEBUG_LOG("Helper exiting");
 
+  SCH_RemoveFileHandler(sock_fd);
+  close(sock_fd);
+
   NKS_Finalise();
   SCK_Finalise();
   SYS_Finalise();
@@ -792,9 +797,8 @@ NKS_PreInitialise(uid_t uid, gid_t gid, int scfilter_level)
     LOG_CloseParentFd();
 
     SCK_CloseSocket(sock_fd1);
-    SCH_AddFileHandler(sock_fd2, SCH_FILE_INPUT, handle_helper_request, NULL);
 
-    run_helper(uid, gid, scfilter_level);
+    run_helper(uid, gid, scfilter_level, sock_fd2);
   }
 
   SCK_CloseSocket(sock_fd2);