git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] fast-import: Don't use a maybe-clobbered errno value

From
Jim Meyering <jim@meyering.net>
Date
Jan 18, 2008, 18:35 UTC
Message-ID
<8763xrgewq.fsf@rho.meyering.net>

Without this change, each diagnostic could use an errno value clobbered by the close or unlink in rollback_lock_file.

Signed-off-by: Jim Meyering <meyering@redhat.com>
---
 fast-import.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/fast-import.c b/fast-import.c
index 5e89eef..45b4edf 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -1541,9 +1541,10 @@ static void dump_marks(void)

 	f = fdopen(mark_fd, "w");
 	if (!f) {
+		int saved_errno = errno;
 		rollback_lock_file(&mark_lock);
 		failure |= error("Unable to write marks file %s: %s",
-			mark_file, strerror(errno));
+			mark_file, strerror(saved_errno));
 		return;
 	}

@@ -1556,16 +1557,18 @@ static void dump_marks(void)

 	dump_marks_helper(f, 0, marks);
 	if (ferror(f) || fclose(f)) {
+		int saved_errno = errno;
 		rollback_lock_file(&mark_lock);
 		failure |= error("Unable to write marks file %s: %s",
-			mark_file, strerror(errno));
+			mark_file, strerror(saved_errno));
 		return;
 	}

 	if (commit_lock_file(&mark_lock)) {
+		int saved_errno = errno;
 		rollback_lock_file(&mark_lock);
 		failure |= error("Unable to commit marks file %s: %s",
-			mark_file, strerror(errno));
+			mark_file, strerror(saved_errno));
 		return;
 	}
 }
--
1.5.4.rc3.31.g669237
Message 1 of 1 in “fast-import: Don't use a maybe-clobbered errno value”
  1. fast-import: Don't use a maybe-clobbered errno valueJim Meyering, Jan 18, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.