free allocated resources on error
Merge pull request #11 from mscdex/master

free allocated resources on error