Be careful about freeing memory in comparator