xdiff/xhistogram: factor out memory cleanup into free_index()