Skip to content

Commit

Permalink
libcore/mmap.cpp: mmap(2) returns MAP_FAILED on error (mitsuba-render…
Browse files Browse the repository at this point in the history
  • Loading branch information
fritschy authored Mar 4, 2020
1 parent 12622b2 commit f539835
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/libcore/mmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ struct MemoryMappedFile::MemoryMappedFilePrivate {
Throw("Could not write to \"%s\"!", filename.string());

data = mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (data == nullptr)
if (data == MAP_FAILED) {
data = nullptr;
Throw("Could not map \"%s\" to memory!", filename.string());
}
if (close(fd) != 0)
Throw("close(): unable to close file!");
#elif defined(__WINDOWS__)
Expand Down Expand Up @@ -88,8 +90,10 @@ struct MemoryMappedFile::MemoryMappedFilePrivate {
Throw("Could not write to \"%s\"!", filename.string());

data = mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (data == nullptr)
if (data == MAP_FAILED) {
data = nullptr;
Throw("Could not map \"%s\" to memory!", filename.string());
}

if (close(fd) != 0)
Throw("close(): unable to close file!");
Expand Down Expand Up @@ -139,8 +143,10 @@ struct MemoryMappedFile::MemoryMappedFilePrivate {
Throw("Could not open \"%s\"!", filename.string());

data = mmap(nullptr, size, PROT_READ | (can_write ? PROT_WRITE : 0), MAP_SHARED, fd, 0);
if (data == nullptr)
if (data == MAP_FAILED) {
data = nullptr;
Throw("Could not map \"%s\" to memory!", filename.string());
}

if (close(fd) != 0)
Throw("close(): unable to close file!");
Expand Down

0 comments on commit f539835

Please sign in to comment.