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

Skip to content

Commit 084f2c4

Browse files
author
Edward Thomson
committed
Merge pull request libgit2#3668 from libgit2/cmn/mwindow-try-harder
mwindow: free unused windows if we fail to mmap
2 parents c68044a + d50fd57 commit 084f2c4

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)