diff -up patch-2.7.6/src/patch.c.git-style patch-2.7.6/src/patch.c --- patch-2.7.6/src/patch.c.git-style 2018-02-03 13:41:49.000000000 +0100 +++ patch-2.7.6/src/patch.c 2018-10-11 15:01:08.709406802 +0200 @@ -1938,8 +1938,12 @@ output_files (struct stat const *st) { gl_list_iterator_t iter; const void *elt; + gl_list_t files; - iter = gl_list_iterator (files_to_output); + files = files_to_output; + init_files_to_output (); + + iter = gl_list_iterator (files); while (gl_list_iterator_next (&iter, &elt, NULL)) { const struct file_to_output *file_to_output = elt; @@ -1957,8 +1961,8 @@ output_files (struct stat const *st) /* Free the list up to here. */ for (;;) { - const void *elt2 = gl_list_get_at (files_to_output, 0); - gl_list_remove_at (files_to_output, 0); + const void *elt2 = gl_list_get_at (files, 0); + gl_list_remove_at (files, 0); if (elt == elt2) break; } @@ -1967,7 +1971,7 @@ output_files (struct stat const *st) } } gl_list_iterator_free (&iter); - gl_list_clear (files_to_output); + gl_list_clear (files); } /* Fatal exit with cleanup. */ diff -up patch-2.7.6/tests/git-error.git-style patch-2.7.6/tests/git-error --- patch-2.7.6/tests/git-error.git-style 2018-10-11 15:00:09.349200685 +0200 +++ patch-2.7.6/tests/git-error 2018-10-11 15:00:09.349200685 +0200 @@ -0,0 +1,29 @@ +# Copyright (C) 2018 Free Software Foundation, Inc. +# +# Copying and distribution of this file, with or without modification, +# in any medium, are permitted without royalty provided the copyright +# notice and this notice are preserved. + +. $srcdir/test-lib.sh + +require cat +use_local_patch +use_tmpdir + +cat > f.diff <