am db1597a9: Fix shutdown sequence to avoid SIGSEGV when running am command

* commit 'db1597a98958b78dc0d8eced19ae1406382b70d6':
  Fix shutdown sequence to avoid SIGSEGV when running am command