prison_deref and prison_deref kill do almost the same thing when they remove a jail's last reference. Put that common code into a new function. There's also an operation that prison_deref_kill does in two places that can also go into a helper function.
The "almost the same thing" is partly because mac_prison_destroy is only called in prison_deref, but it should be called in prison_deref_kill as well. As part of this, the condition for that call changes from "prison is locked" to "prison is invalid" and the assertion is changed to match.