Fix memory leak on failure
Merge pull request #1 from spkrka/master

Fix memory leak on failure