Fixed memort leak bugs