summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 1bc7c13)
raw | patch | inline | side by side (parent: 1bc7c13)
author | Kristian Høgsberg <krh@redhat.com> | |
Tue, 15 Jan 2008 20:00:02 +0000 (15:00 -0500) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Wed, 16 Jan 2008 01:33:53 +0000 (17:33 -0800) |
The codepath to prepare index files for the temporary and next
index file was closing file descriptor it obtained from the
lockfile API by hand, without letting the API know that the fd
should not be doubly closed.
This is not usually a problem (except it may get EBADFD) but if
we opened another fd for an entirely unrelated purpose (say, an
fd used to mmap a packfile) between the time we close the fd to
the index file and the time we commit or rollback the lockfile
(causing it to also try closing the recorded fd), the lockfile
API will close an incorrect file descriptor that is still used
for an entirely unrelated purpose.
There's four close(fd) calls in prepare_index() and they're all
incorrect. The open fd's are cleaned up in rollback_index_files() and
shouldn't be closed manually. The patch below gets rid of the extra
close() calls and should fix the problem.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
index file was closing file descriptor it obtained from the
lockfile API by hand, without letting the API know that the fd
should not be doubly closed.
This is not usually a problem (except it may get EBADFD) but if
we opened another fd for an entirely unrelated purpose (say, an
fd used to mmap a packfile) between the time we close the fd to
the index file and the time we commit or rollback the lockfile
(causing it to also try closing the recorded fd), the lockfile
API will close an incorrect file descriptor that is still used
for an entirely unrelated purpose.
There's four close(fd) calls in prepare_index() and they're all
incorrect. The open fd's are cleaned up in rollback_index_files() and
shouldn't be closed manually. The patch below gets rid of the extra
close() calls and should fix the problem.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin-commit.c | patch | blob | history |
diff --git a/builtin-commit.c b/builtin-commit.c
index 6d2ca808b55136b60e65994e8929c3a068b425d6..16345e9b9332c0e42fb2e61c39dc0534db9f7f8e 100644 (file)
--- a/builtin-commit.c
+++ b/builtin-commit.c
int fd = hold_locked_index(&index_lock, 1);
add_files_to_cache(0, also ? prefix : NULL, pathspec);
refresh_cache(REFRESH_QUIET);
- if (write_cache(fd, active_cache, active_nr) || close(fd))
+ if (write_cache(fd, active_cache, active_nr))
die("unable to write new_index file");
commit_style = COMMIT_NORMAL;
return index_lock.filename;
fd = hold_locked_index(&index_lock, 1);
refresh_cache(REFRESH_QUIET);
if (write_cache(fd, active_cache, active_nr) ||
- close(fd) || commit_locked_index(&index_lock))
+ commit_locked_index(&index_lock))
die("unable to write new_index file");
commit_style = COMMIT_AS_IS;
return get_index_file();
fd = hold_locked_index(&index_lock, 1);
add_remove_files(&partial);
refresh_cache(REFRESH_QUIET);
- if (write_cache(fd, active_cache, active_nr) || close(fd))
+ if (write_cache(fd, active_cache, active_nr))
die("unable to write new_index file");
fd = hold_lock_file_for_update(&false_lock,
add_remove_files(&partial);
refresh_cache(REFRESH_QUIET);
- if (write_cache(fd, active_cache, active_nr) || close(fd))
+ if (write_cache(fd, active_cache, active_nr))
die("unable to write temporary index file");
return false_lock.filename;
}