]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
refclock_rtc: fix finalization with closed descriptor
authorMiroslav Lichvar <mlichvar@redhat.com>
Wed, 11 Jun 2025 11:30:57 +0000 (13:30 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Wed, 11 Jun 2025 11:39:17 +0000 (13:39 +0200)
If the RTC file descriptor was closed and removed after a read error,
don't try to close and remove it again in the driver finalization to
avoid an assertion failure on the negative descriptor.

Fixes: 4f22883f4e71 ("refclock: add new refclock for RTCs")
refclock_rtc.c

index 2fcde948276bb258817a2142916355e68f374ac6..1cde5c08832cdd29a90ee2c708fe9e2497d45cd6 100644 (file)
@@ -138,12 +138,15 @@ static void refrtc_finalise(RCL_Instance instance)
 
   rtc = RCL_GetDriverData(instance);
 
-  if (!rtc->polling) {
-    SCH_RemoveFileHandler(rtc->fd);
-    RTC_Linux_SwitchInterrupt(rtc->fd, 0);
+  if (rtc->fd >= 0) {
+    if (!rtc->polling) {
+      SCH_RemoveFileHandler(rtc->fd);
+      RTC_Linux_SwitchInterrupt(rtc->fd, 0);
+    }
+
+    close(rtc->fd);
   }
 
-  close(rtc->fd);
   Free(rtc);
 }