#1379: fix memory leaks on exceptions
Merge pull request #1390 from sjinks/issue-1379

[1379] Fix memory leaks on exceptions