Fix some memleaks revealed by Coverity Scan