Fixed some memory leaks in the zone generate function