[orbis-kernel] Improve kdelete safety

This commit is contained in:
Ivan Chikish 2023-07-15 19:05:14 +03:00
parent 9717128c1f
commit 191a9459af
5 changed files with 12 additions and 5 deletions

View file

@ -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