1
0
mirror of https://github.com/BurntSushi/ripgrep.git synced 2025-02-04 06:08:39 +02:00

mmap: handle ENOMEM error

This commit causes a memory map strategy to fall back to a file backed
strategy if the mmap call fails with an `ENOMEM` error.

Fixes #852
This commit is contained in:
Andrew Gallant 2018-03-10 08:12:24 -05:00
parent 9163aaac27
commit dbf6f15625
No known key found for this signature in database
GPG Key ID: B2E3A4923F8B0D44

View File

@ -341,14 +341,17 @@ impl Worker {
#[cfg(unix)] #[cfg(unix)]
fn mmap(&self, file: &File) -> Result<Option<Mmap>> { fn mmap(&self, file: &File) -> Result<Option<Mmap>> {
use libc::{ENODEV, EOVERFLOW}; use libc::{EOVERFLOW, ENODEV, ENOMEM};
let err = match mmap_readonly(file) { let err = match mmap_readonly(file) {
Ok(mmap) => return Ok(Some(mmap)), Ok(mmap) => return Ok(Some(mmap)),
Err(err) => err, Err(err) => err,
}; };
let code = err.raw_os_error(); let code = err.raw_os_error();
if code == Some(ENODEV) || code == Some(EOVERFLOW) { if code == Some(EOVERFLOW)
|| code == Some(ENODEV)
|| code == Some(ENOMEM)
{
return Ok(None); return Ok(None);
} }
Err(From::from(err)) Err(From::from(err))