refclock_rtc: fix finalization with closed descriptor

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: 4f22883f4e ("refclock: add new refclock for RTCs")
This commit is contained in:
Miroslav Lichvar
2025-06-11 13:30:57 +02:00
parent df98fb4fc7
commit e463fcab49

View File

@@ -138,12 +138,15 @@ static void refrtc_finalise(RCL_Instance instance)
rtc = RCL_GetDriverData(instance); rtc = RCL_GetDriverData(instance);
if (!rtc->polling) { if (rtc->fd >= 0) {
SCH_RemoveFileHandler(rtc->fd); if (!rtc->polling) {
RTC_Linux_SwitchInterrupt(rtc->fd, 0); SCH_RemoveFileHandler(rtc->fd);
RTC_Linux_SwitchInterrupt(rtc->fd, 0);
}
close(rtc->fd);
} }
close(rtc->fd);
Free(rtc); Free(rtc);
} }