From: Miroslav Lichvar Date: Wed, 11 Jun 2025 11:30:57 +0000 (+0200) Subject: refclock_rtc: fix finalization with closed descriptor X-Git-Tag: 4.7~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e463fcab49ddfcc727f35e5bb1f895ab1fb89fa5;p=thirdparty%2Fchrony.git 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: 4f22883f4e71 ("refclock: add new refclock for RTCs") --- diff --git a/refclock_rtc.c b/refclock_rtc.c index 2fcde948..1cde5c08 100644 --- a/refclock_rtc.c +++ b/refclock_rtc.c @@ -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); }