From c4712e4553f13d87d655325a57538f299402d457 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sun, 24 Dec 2006 00:47:23 -0500 Subject: Replace mmap with xmmap, better handling MAP_FAILED. In some cases we did not even bother to check the return value of mmap() and just assume it worked. This is bad, because if we are out of virtual address space the kernel returned MAP_FAILED and we would attempt to dereference that address, segfaulting without any real error output to the user. We are replacing all calls to mmap() with xmmap() and moving all MAP_FAILED checking into that single location. If a mmap call fails we try to release enough least-recently-used pack windows to possibly succeed, then retry the mmap() attempt. If we cannot mmap even after releasing pack memory then we die() as none of our callers have any reasonable recovery strategy for a failed mmap. Signed-off-by: Shawn O. Pearce Signed-off-by: Junio C Hamano --- diff.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'diff.c') diff --git a/diff.c b/diff.c index f14288bb8a..244292a70c 100644 --- a/diff.c +++ b/diff.c @@ -1341,10 +1341,8 @@ int diff_populate_filespec(struct diff_filespec *s, int size_only) fd = open(s->path, O_RDONLY); if (fd < 0) goto err_empty; - s->data = mmap(NULL, s->size, PROT_READ, MAP_PRIVATE, fd, 0); + s->data = xmmap(NULL, s->size, PROT_READ, MAP_PRIVATE, fd, 0); close(fd); - if (s->data == MAP_FAILED) - goto err_empty; s->should_munmap = 1; } else { -- cgit v1.2.3