Skip to content

Commit 5a7b1b5

Browse files
meyeringgitster
authored andcommitted
fast-import: Don't use a maybe-clobbered errno value
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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 1812564 commit 5a7b1b5

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

fast-import.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1541,9 +1541,10 @@ static void dump_marks(void)
15411541

15421542
f = fdopen(mark_fd, "w");
15431543
if (!f) {
1544+
int saved_errno = errno;
15441545
rollback_lock_file(&mark_lock);
15451546
failure |= error("Unable to write marks file %s: %s",
1546-
mark_file, strerror(errno));
1547+
mark_file, strerror(saved_errno));
15471548
return;
15481549
}
15491550

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

15571558
dump_marks_helper(f, 0, marks);
15581559
if (ferror(f) || fclose(f)) {
1560+
int saved_errno = errno;
15591561
rollback_lock_file(&mark_lock);
15601562
failure |= error("Unable to write marks file %s: %s",
1561-
mark_file, strerror(errno));
1563+
mark_file, strerror(saved_errno));
15621564
return;
15631565
}
15641566

15651567
if (commit_lock_file(&mark_lock)) {
1568+
int saved_errno = errno;
15661569
rollback_lock_file(&mark_lock);
15671570
failure |= error("Unable to commit marks file %s: %s",
1568-
mark_file, strerror(errno));
1571+
mark_file, strerror(saved_errno));
15691572
return;
15701573
}
15711574
}

0 commit comments

Comments
 (0)