diff options
author | Timothy Flynn <trflynn89@pm.me> | 2023-04-24 11:25:14 -0400 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-04-24 18:21:01 +0200 |
commit | 8b7c5db1867b9637e5b73a25a2e1aa469c52f15c (patch) | |
tree | 97c5b4b2b65733cc3986ac859e888d25260e0853 /Userland | |
parent | 683c8284cfcf157a726ee5bcd92f51f7b9861bc1 (diff) | |
download | serenity-8b7c5db1867b9637e5b73a25a2e1aa469c52f15c.zip |
LibVideo: Do not invoke Vector2D's destructor in order to resize it
This leads to all kinds of undefined behavior, especially when callers
have a view into the Vector2D.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibVideo/VP9/ContextStorage.h | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/Userland/Libraries/LibVideo/VP9/ContextStorage.h b/Userland/Libraries/LibVideo/VP9/ContextStorage.h index 5bb0d709e0..eb40d28d6d 100644 --- a/Userland/Libraries/LibVideo/VP9/ContextStorage.h +++ b/Userland/Libraries/LibVideo/VP9/ContextStorage.h @@ -103,17 +103,14 @@ class Vector2D { public: ~Vector2D() { - if (m_storage) - free(m_storage); - m_storage = nullptr; - m_width = 0; - m_height = 0; + clear_storage(); } ErrorOr<void> try_resize(u32 height, u32 width) { if (height != m_height && width != m_width) { - this->~Vector2D(); + clear_storage(); + size_t size = height * width; auto* new_storage = static_cast<T*>(malloc(size * sizeof(T))); if (!new_storage) @@ -195,6 +192,15 @@ public: } private: + void clear_storage() + { + if (m_storage) + free(m_storage); + m_storage = nullptr; + m_width = 0; + m_height = 0; + } + u32 m_height { 0 }; u32 m_width { 0 }; T* m_storage { nullptr }; |