aboutsummaryrefslogtreecommitdiffstats
path: root/rev-cache.c
diff options
context:
space:
mode:
authorPavel Roskin <proski@gnu.org>2005-07-29 10:49:14 -0400
committerJunio C Hamano <junkio@cox.net>2005-07-29 17:21:48 -0700
commite35f9824159bba94eecdf22d198799701ed60940 (patch)
tree0d1d08eec92d179ce02b4c4b5e961e0f6c1feddc /rev-cache.c
parent1df092d211868b3b74f5b3981fad9b195a0bedad (diff)
downloadgit-e35f9824159bba94eecdf22d198799701ed60940.tar.gz
[PATCH] mmap error handling
I have reviewed all occurrences of mmap() in git and fixed three types of errors/defects: 1) The result is not checked. 2) The file descriptor is closed if mmap() succeeds, but not when it fails. 3) Various casts applied to -1 are used instead of MAP_FAILED, which is specifically defined to check mmap() return value. [jc: This is a second round of Pavel's patch. He fixed up the problem that close() potentially clobbering the errno from mmap, which the first round had.] Signed-off-by: Pavel Roskin <proski@gnu.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'rev-cache.c')
-rw-r--r--rev-cache.c6
1 files changed, 2 insertions, 4 deletions
diff --git a/rev-cache.c b/rev-cache.c
index ea65274ed0..f908ce7a3a 100644
--- a/rev-cache.c
+++ b/rev-cache.c
@@ -212,11 +212,9 @@ int read_rev_cache(const char *path, FILE *dumpfile, int dry_run)
return -1;
}
map = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
- if (map == MAP_FAILED) {
- close(fd);
- return -1;
- }
close(fd);
+ if (map == MAP_FAILED)
+ return -1;
memset(last_sha1, 0, 20);
ofs = 0;