fixed memory leak if fail to build