Lock maint_lock on rpzs when detaching from an rpz, to make sure nobody changes anything. We set 'updaterunning' only after the first event was fired. We could have a race when we:
- send the event to updater task, updatepending=true, updaterunning=false
- shutdown, since updaterunning == false we don't purge events from task and free task structure that's enqueued
- task processed the, now freed, event, crash Fixed it by purging the event if it's linked. We detached updater task before all the events have been processed, now detach it only after all rpzs have been detached.