Fix issues with teardown when builds are cancelled

- If a build was cancelled during slave setup, the master
tried to deallocate and teardown the slave twice.
- If a build was cancelled and then the master received more than
one subjob result, the master tried to perform postbuild tasks multiple
times