mirror of
https://github.com/vimpunk/mio.git
synced 2025-12-06 16:57:01 +08:00
Fix not releasing file handle on unsuccessful mapping on win32
This commit is contained in:
parent
76251b8dde
commit
b296e2d40f
@ -183,6 +183,8 @@ inline mmap_context memory_map(const file_handle_type file_handle, const int64_t
|
|||||||
length_to_map));
|
length_to_map));
|
||||||
if(mapping_start == nullptr)
|
if(mapping_start == nullptr)
|
||||||
{
|
{
|
||||||
|
// Close file handle if mapping it failed.
|
||||||
|
::CloseHandle(file_mapping_handle);
|
||||||
error = detail::last_error();
|
error = detail::last_error();
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
@ -438,14 +440,14 @@ void basic_mmap<AccessMode, ByteT>::swap(basic_mmap& other)
|
|||||||
if(this != &other)
|
if(this != &other)
|
||||||
{
|
{
|
||||||
using std::swap;
|
using std::swap;
|
||||||
swap(data_, other.data_);
|
swap(data_, other.data_);
|
||||||
swap(file_handle_, other.file_handle_);
|
swap(file_handle_, other.file_handle_);
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
swap(file_mapping_handle_, other.file_mapping_handle_);
|
swap(file_mapping_handle_, other.file_mapping_handle_);
|
||||||
#endif
|
#endif
|
||||||
swap(length_, other.length_);
|
swap(length_, other.length_);
|
||||||
swap(mapped_length_, other.mapped_length_);
|
swap(mapped_length_, other.mapped_length_);
|
||||||
swap(is_handle_internal_, other.is_handle_internal_);
|
swap(is_handle_internal_, other.is_handle_internal_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -925,6 +925,8 @@ inline mmap_context memory_map(const file_handle_type file_handle, const int64_t
|
|||||||
length_to_map));
|
length_to_map));
|
||||||
if(mapping_start == nullptr)
|
if(mapping_start == nullptr)
|
||||||
{
|
{
|
||||||
|
// Close file handle if mapping it failed.
|
||||||
|
::CloseHandle(file_mapping_handle);
|
||||||
error = detail::last_error();
|
error = detail::last_error();
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
@ -1180,14 +1182,14 @@ void basic_mmap<AccessMode, ByteT>::swap(basic_mmap& other)
|
|||||||
if(this != &other)
|
if(this != &other)
|
||||||
{
|
{
|
||||||
using std::swap;
|
using std::swap;
|
||||||
swap(data_, other.data_);
|
swap(data_, other.data_);
|
||||||
swap(file_handle_, other.file_handle_);
|
swap(file_handle_, other.file_handle_);
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
swap(file_mapping_handle_, other.file_mapping_handle_);
|
swap(file_mapping_handle_, other.file_mapping_handle_);
|
||||||
#endif
|
#endif
|
||||||
swap(length_, other.length_);
|
swap(length_, other.length_);
|
||||||
swap(mapped_length_, other.mapped_length_);
|
swap(mapped_length_, other.mapped_length_);
|
||||||
swap(is_handle_internal_, other.is_handle_internal_);
|
swap(is_handle_internal_, other.is_handle_internal_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user