mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-06 09:36:08 +00:00
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.
This commit is contained in:
parent
bb045b3c70
commit
f9d8e42636
Notes:
sideshowbarker
2024-07-17 07:11:12 +09:00
Author: https://github.com/trflynn89
Commit: f9d8e42636
Pull-request: https://github.com/SerenityOS/serenity/pull/18494
Reviewed-by: https://github.com/Hendiadyoin1
1 changed files with 2 additions and 3 deletions
|
@ -112,7 +112,7 @@ public:
|
||||||
clear_storage();
|
clear_storage();
|
||||||
|
|
||||||
size_t size = height * width;
|
size_t size = height * width;
|
||||||
auto* new_storage = static_cast<T*>(malloc(size * sizeof(T)));
|
auto* new_storage = new (nothrow) T[size];
|
||||||
if (!new_storage)
|
if (!new_storage)
|
||||||
return Error::from_errno(ENOMEM);
|
return Error::from_errno(ENOMEM);
|
||||||
m_storage = new_storage;
|
m_storage = new_storage;
|
||||||
|
@ -194,8 +194,7 @@ public:
|
||||||
private:
|
private:
|
||||||
void clear_storage()
|
void clear_storage()
|
||||||
{
|
{
|
||||||
if (m_storage)
|
delete[] m_storage;
|
||||||
free(m_storage);
|
|
||||||
m_storage = nullptr;
|
m_storage = nullptr;
|
||||||
m_width = 0;
|
m_width = 0;
|
||||||
m_height = 0;
|
m_height = 0;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue