mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-30 14:07:59 +00:00
Fix a race condition between shutdown and route_connected()
When shutting down, the interface manager can be destroyed before the `route_connected()` callback is called, which is unexpected for the latter and can cause a crash. Move the interface manager attachment code from the callback to the place before the callback is registered using `isc_nm_routeconnect()` function, which will make sure that the interface manager will live at least until the callback is called. Make sure to detach the interface manager if the `isc_nm_routeconnect()` function is not implemented, or when the callback is called with a result value which differs from `ISC_R_SUCCESS`.
This commit is contained in:
@@ -262,12 +262,12 @@ route_connected(isc_nmhandle_t *handle, isc_result_t eresult, void *arg) {
|
||||
"route_connected: %s", isc_result_totext(eresult));
|
||||
|
||||
if (eresult != ISC_R_SUCCESS) {
|
||||
ns_interfacemgr_detach(&mgr);
|
||||
return;
|
||||
}
|
||||
|
||||
INSIST(mgr->route == NULL);
|
||||
|
||||
ns_interfacemgr_attach(mgr, &(ns_interfacemgr_t *){ NULL });
|
||||
isc_nmhandle_attach(handle, &mgr->route);
|
||||
isc_nm_read(handle, route_recv, mgr);
|
||||
}
|
||||
@@ -345,7 +345,14 @@ ns_interfacemgr_create(isc_mem_t *mctx, ns_server_t *sctx,
|
||||
}
|
||||
|
||||
if (scan) {
|
||||
result = isc_nm_routeconnect(nm, route_connected, mgr);
|
||||
ns_interfacemgr_t *imgr = NULL;
|
||||
|
||||
ns_interfacemgr_attach(mgr, &imgr);
|
||||
|
||||
result = isc_nm_routeconnect(nm, route_connected, imgr);
|
||||
if (result == ISC_R_NOTIMPLEMENTED) {
|
||||
ns_interfacemgr_detach(&imgr);
|
||||
}
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
isc_log_write(IFMGR_COMMON_LOGARGS, ISC_LOG_INFO,
|
||||
"unable to open route socket: %s",
|
||||
|
Reference in New Issue
Block a user