fix memory leak on thrown exception
Merge pull request #169 from mscdex/patch-1

fix memory leak on thrown exception