Fix #1567
Test case for #1567
Update test case for #1498
Merge pull request #1574 from sjinks/issue-1567

Fix segfault in post-deactivate hook