mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2026-10-19 11:19:36 +00:00
Clarify the MAP_FAILED guard comment and assert the cleared size
Explain why `addr_` is reset before `close()`: `munmap()` must not be called with the sentinel. The test also checks `size()`, since the hazard is a stale size paired with a sentinel `data()`.
This commit is contained in:
1 parent
2e37c51921
commit
15a23abd7e
2 files changed
+6
-7
No files matched your search
@@ -5577,10 +5577,9 @@ inline bool mmap::open(const char *path) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// A failed mapping must not be left in `addr_`: `is_open()` only compares it
|
||||
// against nullptr, so the MAP_FAILED sentinel would pass and `data()` would
|
||||
// hand the caller (const char *)-1.
|
||||
if (addr_ == MAP_FAILED) {
|
||||
// Clear the sentinel before `close()`, since `is_open()` only checks
|
||||
// `addr_` against nullptr and `munmap()` must not be called with it.
|
||||
addr_ = nullptr;
|
||||
close();
|
||||
return false;
|
||||
|
||||
Reference in new issue
Block a user