commit-graph: clean up leaked memory during write