fixed memory leaks caused by memory owned by vars