patch/backport-Abort-when-cleaning-up-fails.patch
Xibo.Wang 3e3761cbac Bakport commits from upstream
1. Skip "ed" test when the ed utility is not installed
	https://git.savannah.gnu.org/gitweb/?p=patch.git;a=commit;h=a5b442c
2. Abort when cleaning up fails
	https://git.savannah.gnu.org/gitweb/?p=patch.git;a=commit;h=b7b028a
3. Don't crash when RLIMIT_NOFILE is set to RLIM_INFINITY
	https://git.savannah.gnu.org/gitweb/?p=patch.git;a=commit;h=61d7788
4. Avoid invalid memory access in context format diffs
	https://git.savannah.gnu.org/gitweb/?p=patch.git;a=commit;h=15b158d
5. Fix failed assertion 'outstate->after_newline'
	https://git.savannah.gnu.org/gitweb/?p=patch.git;a=commit;h=76e7758
6. Add missing-section tests to context-format test case
	https://git.savannah.gnu.org/gitweb/?p=patch.git;a=commit;h=78ed9de
7. Fix test for presence of BASH_LINENO[0]
	https://git.savannah.gnu.org/gitweb/?p=patch.git;a=commit;h=7623b2d
2022-12-30 16:04:49 +08:00

54 lines
1.5 KiB
Diff

From b5c17c6c6591e62173197f97d3113862bf23bd4d Mon Sep 17 00:00:00 2001
From: Andreas Gruenbacher <agruen@gnu.org>
Date: Fri, 28 Jun 2019 00:30:25 +0200
Subject: [PATCH 2/8] Abort when cleaning up fails
When a fatal error triggers during cleanup, another attempt will be made to
clean up, which will likely lead to the same fatal error. So instead, bail out
when that happens.
src/patch.c (cleanup): Bail out when called recursively.
(main): There is no need to call output_files() before cleanup() as cleanup()
already does that.
Signed-off-by: Xibo.Wang <wangxb12@chinatelecom.cn>
---
src/patch.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/src/patch.c b/src/patch.c
index e57cf19..1e1915d 100644
--- a/src/patch.c
+++ b/src/patch.c
@@ -685,7 +685,6 @@ main (int argc, char **argv)
}
if (outstate.ofp && (ferror (outstate.ofp) || fclose (outstate.ofp) != 0))
write_fatal ();
- output_files (NULL);
cleanup ();
delete_files ();
if (somefailed)
@@ -1991,7 +1990,6 @@ void
fatal_exit (int sig)
{
cleanup ();
-
if (sig)
exit_with_signal (sig);
@@ -2011,6 +2009,12 @@ remove_if_needed (char const *name, bool *needs_removal)
static void
cleanup (void)
{
+ static bool already_cleaning_up;
+
+ if (already_cleaning_up)
+ return;
+ already_cleaning_up = true;
+
remove_if_needed (TMPINNAME, &TMPINNAME_needs_removal);
remove_if_needed (TMPOUTNAME, &TMPOUTNAME_needs_removal);
remove_if_needed (TMPPATNAME, &TMPPATNAME_needs_removal);
--
1.8.3.1