From 5f6f265f8089904f45d95b985b0e603a47562ecf Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Thu, 21 May 2020 11:47:38 +0200 Subject: [PATCH] local: don't remove handlers in finalization Require all handlers to be deregistered by their users before the local finalization. --- local.c | 12 +++++------- manual.c | 1 + ntp_sources.c | 2 ++ reference.c | 2 ++ rtc_linux.c | 4 ++++ smooth.c | 4 ++++ sys_generic.c | 2 ++ 7 files changed, 20 insertions(+), 7 deletions(-) diff --git a/local.c b/local.c index b4baaac..15c37b1 100644 --- a/local.c +++ b/local.c @@ -185,13 +185,11 @@ LCL_Initialise(void) void LCL_Finalise(void) { - while (change_list.next != &change_list) - LCL_RemoveParameterChangeHandler(change_list.next->handler, - change_list.next->anything); - - while (dispersion_notify_list.next != &dispersion_notify_list) - LCL_RemoveDispersionNotifyHandler(dispersion_notify_list.next->handler, - dispersion_notify_list.next->anything); + /* Make sure all handlers have been removed */ + if (change_list.next != &change_list) + assert(0); + if (dispersion_notify_list.next != &dispersion_notify_list) + assert(0); } /* ================================================== */ diff --git a/manual.c b/manual.c index bf52d14..98a3aa2 100644 --- a/manual.c +++ b/manual.c @@ -92,6 +92,7 @@ MNL_Initialise(void) void MNL_Finalise(void) { + LCL_RemoveParameterChangeHandler(slew_samples, NULL); } /* ================================================== */ diff --git a/ntp_sources.c b/ntp_sources.c index db6cbc8..4a54854 100644 --- a/ntp_sources.c +++ b/ntp_sources.c @@ -185,6 +185,8 @@ NSR_Finalise(void) clean_source_record(record); } + LCL_RemoveParameterChangeHandler(slew_sources, NULL); + ARR_DestroyInstance(records); ARR_DestroyInstance(pools); diff --git a/reference.c b/reference.c index 553bc96..7423487 100644 --- a/reference.c +++ b/reference.c @@ -304,6 +304,8 @@ REF_Finalise(void) update_drift_file(LCL_ReadAbsoluteFrequency(), our_skew); } + LCL_RemoveParameterChangeHandler(handle_slew, NULL); + Free(fb_drifts); initialised = 0; diff --git a/rtc_linux.c b/rtc_linux.c index a44a912..08c2a19 100644 --- a/rtc_linux.c +++ b/rtc_linux.c @@ -573,6 +573,10 @@ RTC_Linux_Finalise(void) (void) RTC_Linux_WriteParameters(); } + + if (rtc_sec) + LCL_RemoveParameterChangeHandler(slew_samples, NULL); + Free(rtc_sec); Free(rtc_trim); Free(system_times); diff --git a/smooth.c b/smooth.c index 4125ea0..4c350e9 100644 --- a/smooth.c +++ b/smooth.c @@ -272,6 +272,10 @@ void SMT_Initialise(void) void SMT_Finalise(void) { + if (!enabled) + return; + + LCL_RemoveParameterChangeHandler(handle_slew, NULL); } int SMT_IsEnabled(void) diff --git a/sys_generic.c b/sys_generic.c index 9c785d2..6e29ee2 100644 --- a/sys_generic.c +++ b/sys_generic.c @@ -417,6 +417,8 @@ SYS_Generic_Finalise(void) LCL_ReadRawTime(&now); stop_fastslew(&now); + + LCL_RemoveParameterChangeHandler(handle_step, NULL); } /* ================================================== */