Fix memory leak on thrown exception

Issue(s) found via [cppcheck](http://cppcheck.sourceforge.net/).