mirror of
https://github.com/RPCSX/rpcsx.git
synced 2026-04-06 06:55:09 +00:00
[orbis-kernel] Improve kdelete safety
This commit is contained in:
parent
9717128c1f
commit
191a9459af
5 changed files with 12 additions and 5 deletions
|
|
@ -54,9 +54,16 @@ template <typename T, typename... Args> T *knew(Args &&...args) {
|
|||
return res;
|
||||
}
|
||||
|
||||
// clang-format off
|
||||
template <typename T> void kdelete(T *ptr) {
|
||||
auto total_size = sizeof(T);
|
||||
if constexpr (requires(T *t) { t->_total_size = sizeof(T); })
|
||||
total_size = ptr->_total_size;
|
||||
else
|
||||
static_assert(std::is_final_v<T>, "Uncertain type size");
|
||||
ptr->~T();
|
||||
utils::kfree(ptr, sizeof(T));
|
||||
utils::kfree(ptr, total_size);
|
||||
}
|
||||
// clang-format on
|
||||
|
||||
} // namespace orbis
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue