path: root/refs.c
diff options
authorShawn O. Pearce <>2006-12-24 05:47:23 (GMT)
committerJunio C Hamano <>2006-12-29 19:36:45 (GMT)
commitc4712e4553f13d87d655325a57538f299402d457 (patch)
treed09717f9d9a811d36ae5572b131a5b40e1dfcdcf /refs.c
parent97bfeb34df1aa8a1cf232278624a5a5c924ee380 (diff)
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 <>
Diffstat (limited to 'refs.c')
1 files changed, 1 insertions, 1 deletions
diff --git a/refs.c b/refs.c
index e88ed8b..121774c 100644
--- a/refs.c
+++ b/refs.c
@@ -1026,7 +1026,7 @@ int read_ref_at(const char *ref, unsigned long at_time, int cnt, unsigned char *
fstat(logfd, &st);
if (!st.st_size)
die("Log %s is empty.", logfile);
- logdata = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, logfd, 0);
+ logdata = xmmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, logfd, 0);
lastrec = NULL;