From f9d8e42636c9f72f88e97b33a44b1d020641bdb1 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Mon, 24 Apr 2023 12:47:15 -0400 Subject: [PATCH] LibVideo: Allocate Vector2D underlying storage with new, not malloc Using malloc does not invoke T's constructor, nor were were invoking T's constructor ourselves. Accessing T without invoking its constructor is undefined behavior. --- Userland/Libraries/LibVideo/VP9/ContextStorage.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Userland/Libraries/LibVideo/VP9/ContextStorage.h b/Userland/Libraries/LibVideo/VP9/ContextStorage.h index eb40d28d6d..a91175fc14 100644 --- a/Userland/Libraries/LibVideo/VP9/ContextStorage.h +++ b/Userland/Libraries/LibVideo/VP9/ContextStorage.h @@ -112,7 +112,7 @@ public: clear_storage(); size_t size = height * width; - auto* new_storage = static_cast(malloc(size * sizeof(T))); + auto* new_storage = new (nothrow) T[size]; if (!new_storage) return Error::from_errno(ENOMEM); m_storage = new_storage; @@ -194,8 +194,7 @@ public: private: void clear_storage() { - if (m_storage) - free(m_storage); + delete[] m_storage; m_storage = nullptr; m_width = 0; m_height = 0;