mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 06:27:45 +00:00
Kernel: Stop leaking TmpFS inodes
TmpFS inodes rely on the call to Inode::one_ref_left() to unregister themselves from the inode cache in TmpFS. When moving various kernel classes to ListedRefCounted for safe unref() while participating on lists, I forgot to make ListedRefCounted check for (and call) one_ref_left() & will_be_destroyed() on the CRTP class.
This commit is contained in:
parent
049d846eb9
commit
5159f64117
1 changed files with 11 additions and 7 deletions
|
@ -20,15 +20,19 @@ class ListedRefCounted : public RefCountedBase {
|
||||||
public:
|
public:
|
||||||
bool unref() const
|
bool unref() const
|
||||||
{
|
{
|
||||||
bool did_hit_zero = T::all_instances().with([&](auto& list) {
|
auto new_ref_count = T::all_instances().with([&](auto& list) {
|
||||||
if (deref_base())
|
auto new_ref_count = deref_base();
|
||||||
return false;
|
if (new_ref_count == 0)
|
||||||
list.remove(const_cast<T&>(static_cast<T const&>(*this)));
|
list.remove(const_cast<T&>(static_cast<T const&>(*this)));
|
||||||
return true;
|
return new_ref_count;
|
||||||
});
|
});
|
||||||
if (did_hit_zero)
|
if (new_ref_count == 0) {
|
||||||
|
call_will_be_destroyed_if_present(static_cast<const T*>(this));
|
||||||
delete const_cast<T*>(static_cast<T const*>(this));
|
delete const_cast<T*>(static_cast<T const*>(this));
|
||||||
return did_hit_zero;
|
} else if (new_ref_count == 1) {
|
||||||
|
call_one_ref_left_if_present(static_cast<T const*>(this));
|
||||||
|
}
|
||||||
|
return new_ref_count == 0;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue