mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 15:05:08 +00:00
Kernel: Make InodeWatcher::crate API OOM safe
This commit is contained in:
parent
c8758d4faa
commit
0d50d3ed1e
3 changed files with 21 additions and 7 deletions
|
@ -12,9 +12,12 @@
|
||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
|
|
||||||
NonnullRefPtr<InodeWatcher> InodeWatcher::create()
|
KResultOr<NonnullRefPtr<InodeWatcher>> InodeWatcher::create()
|
||||||
{
|
{
|
||||||
return adopt_ref(*new InodeWatcher);
|
auto watcher = adopt_ref_if_nonnull(new InodeWatcher);
|
||||||
|
if (watcher)
|
||||||
|
return watcher.release_nonnull();
|
||||||
|
return ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
InodeWatcher::~InodeWatcher()
|
InodeWatcher::~InodeWatcher()
|
||||||
|
@ -120,7 +123,11 @@ KResultOr<int> InodeWatcher::register_inode(Inode& inode, unsigned event_mask)
|
||||||
m_wd_counter = 1;
|
m_wd_counter = 1;
|
||||||
} while (m_wd_to_watches.find(wd) != m_wd_to_watches.end());
|
} while (m_wd_to_watches.find(wd) != m_wd_to_watches.end());
|
||||||
|
|
||||||
auto description = WatchDescription::create(wd, inode, event_mask);
|
auto description_or_error = WatchDescription::create(wd, inode, event_mask);
|
||||||
|
if (description_or_error.is_error())
|
||||||
|
return description_or_error.error();
|
||||||
|
|
||||||
|
auto description = description_or_error.release_value();
|
||||||
m_inode_to_watches.set(inode.identifier(), description.ptr());
|
m_inode_to_watches.set(inode.identifier(), description.ptr());
|
||||||
m_wd_to_watches.set(wd, move(description));
|
m_wd_to_watches.set(wd, move(description));
|
||||||
|
|
||||||
|
|
|
@ -25,9 +25,12 @@ struct WatchDescription {
|
||||||
Inode& inode;
|
Inode& inode;
|
||||||
unsigned event_mask;
|
unsigned event_mask;
|
||||||
|
|
||||||
static NonnullOwnPtr<WatchDescription> create(int wd, Inode& inode, unsigned event_mask)
|
static KResultOr<NonnullOwnPtr<WatchDescription>> create(int wd, Inode& inode, unsigned event_mask)
|
||||||
{
|
{
|
||||||
return adopt_own(*new WatchDescription(wd, inode, event_mask));
|
auto description = adopt_own_if_nonnull(new WatchDescription(wd, inode, event_mask));
|
||||||
|
if (description)
|
||||||
|
return description.release_nonnull();
|
||||||
|
return ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -41,7 +44,7 @@ private:
|
||||||
|
|
||||||
class InodeWatcher final : public File {
|
class InodeWatcher final : public File {
|
||||||
public:
|
public:
|
||||||
static NonnullRefPtr<InodeWatcher> create();
|
static KResultOr<NonnullRefPtr<InodeWatcher>> create();
|
||||||
virtual ~InodeWatcher() override;
|
virtual ~InodeWatcher() override;
|
||||||
|
|
||||||
virtual bool can_read(const FileDescription&, size_t) const override;
|
virtual bool can_read(const FileDescription&, size_t) const override;
|
||||||
|
|
|
@ -21,7 +21,11 @@ KResultOr<int> Process::sys$create_inode_watcher(u32 flags)
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return fd;
|
return fd;
|
||||||
|
|
||||||
auto description_or_error = FileDescription::create(*InodeWatcher::create());
|
auto watcher_or_error = InodeWatcher::create();
|
||||||
|
if (watcher_or_error.is_error())
|
||||||
|
return watcher_or_error.error();
|
||||||
|
|
||||||
|
auto description_or_error = FileDescription::create(*watcher_or_error.value());
|
||||||
if (description_or_error.is_error())
|
if (description_or_error.is_error())
|
||||||
return description_or_error.error();
|
return description_or_error.error();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue