Fix crash caused by race condition in timer creation

The race condition is the timer elapses before isc__timer_create()
returns the pointer to the caller.  Assigning the return pointer before
enabling the timer will fix it.
This commit is contained in:
Zhaolong Zhang
2018-09-16 19:57:08 -07:00
committed by Michał Kępień
parent 37e834defc
commit 21966423cd

View File

@@ -398,8 +398,10 @@ isc__timer_create(isc_timermgr_t *manager0, isc_timertype_t type,
result = schedule(timer, &now, true);
else
result = ISC_R_SUCCESS;
if (result == ISC_R_SUCCESS)
if (result == ISC_R_SUCCESS) {
*timerp = (isc_timer_t *)timer;
APPEND(manager->timers, timer, link);
}
UNLOCK(&manager->lock);
@@ -412,8 +414,6 @@ isc__timer_create(isc_timermgr_t *manager0, isc_timertype_t type,
return (result);
}
*timerp = (isc_timer_t *)timer;
return (ISC_R_SUCCESS);
}