mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 03:37:34 +00:00
Kernel: Get RefPtr<Device> from the DeviceManagement::get_device method
Instead of returning a raw pointer, which could be technically invalid when using it in the caller function, we return a valid RefPtr of such device. This ensures that the code in DevPtsFS is now safe from a rare race condition in which the SlavePTY device is gone but we still have a pointer to it.
This commit is contained in:
parent
5dcf03ad9a
commit
11ead5c84f
6 changed files with 24 additions and 16 deletions
|
@ -42,13 +42,13 @@ DeviceManagement& DeviceManagement::the()
|
|||
return *s_the;
|
||||
}
|
||||
|
||||
Device* DeviceManagement::get_device(MajorNumber major, MinorNumber minor)
|
||||
RefPtr<Device> DeviceManagement::get_device(MajorNumber major, MinorNumber minor)
|
||||
{
|
||||
return m_devices.with([&](auto& map) -> Device* {
|
||||
return m_devices.with([&](auto& map) -> RefPtr<Device> {
|
||||
auto it = map.find(encoded_device(major.value(), minor.value()));
|
||||
if (it == map.end())
|
||||
return nullptr;
|
||||
return it->value;
|
||||
return *it->value;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue