Fix memory leaks in mapgen