Fix memleak revealed by Coverity Scan
Merge pull request #309 from LebedevRI/coverity-scan-memleaks

Fix some memleaks revealed by Coverity Scan