consistent use of goto out in main
don't need to check for NULL there
Merge pull request #232 from DRMacIver/teardown_on_error

consistent use of goto out in main