Fix segfault in post-deactivate hook

See #1567