Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d50fd57

Browse files
committed
mwindow: free unused windows if we fail to mmap
The first time may be due to memory fragmentation or just bad luck on a 32-bit system. When we hit the mmap error for the first time, free up the unused windows and try again.
1 parent c68044a commit d50fd57

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/mwindow.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,18 @@ static git_mwindow *new_window(
296296
*/
297297

298298
if (git_futils_mmap_ro(&w->window_map, fd, w->offset, (size_t)len) < 0) {
299-
git__free(w);
300-
return NULL;
299+
/*
300+
* The first error might be down to memory fragmentation even if
301+
* we're below our soft limits, so free up what we can and try again.
302+
*/
303+
304+
while (git_mwindow_close_lru(mwf) == 0)
305+
/* nop */;
306+
307+
if (git_futils_mmap_ro(&w->window_map, fd, w->offset, (size_t)len) < 0) {
308+
git__free(w);
309+
return NULL;
310+
}
301311
}
302312

303313
ctl->mmap_calls++;

0 commit comments

Comments
 (0)