merge-file: fix memory leaks on error path