diff options
author | Ben Wiederhake <BenWiederhake.GitHub@gmx.de> | 2021-09-16 23:33:11 +0200 |
---|---|---|
committer | Ali Mohammad Pur <Ali.mpfard@gmail.com> | 2021-09-20 17:39:36 +0430 |
commit | 750bed254fd3db6749e0961051080e26ccc388a7 (patch) | |
tree | 79be693d0bfcae0233fd972cfe1ebe0988321691 /Userland | |
parent | 05006e63c493960e220d4f31d83c95af55bad48b (diff) | |
download | serenity-750bed254fd3db6749e0961051080e26ccc388a7.zip |
LibPDF: Switch to automatic ref counting, fix memory leak
At least `Value::operator=` didn't properly unref the `PDF::Object` when
it was called. This type of problem is removed by just letting `RefPtr`
do its thing.
This patch increases the memory consumption by LibPDF by 4 bytes (the
other union objects) per value.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibPDF/Value.cpp | 8 | ||||
-rw-r--r-- | Userland/Libraries/LibPDF/Value.h | 7 |
2 files changed, 3 insertions, 12 deletions
diff --git a/Userland/Libraries/LibPDF/Value.cpp b/Userland/Libraries/LibPDF/Value.cpp index 887cda9bda..63a699c295 100644 --- a/Userland/Libraries/LibPDF/Value.cpp +++ b/Userland/Libraries/LibPDF/Value.cpp @@ -9,12 +9,6 @@ namespace PDF { -Value::~Value() -{ - if (is_object()) - m_as_object->unref(); -} - Value& Value::operator=(Value const& other) { m_type = other.m_type; @@ -36,8 +30,6 @@ Value& Value::operator=(Value const& other) break; case Type::Object: m_as_object = other.m_as_object; - if (m_as_object) - m_as_object->ref(); break; } return *this; diff --git a/Userland/Libraries/LibPDF/Value.h b/Userland/Libraries/LibPDF/Value.h index 160edd68ba..33f13a0687 100644 --- a/Userland/Libraries/LibPDF/Value.h +++ b/Userland/Libraries/LibPDF/Value.h @@ -7,6 +7,7 @@ #pragma once #include <AK/Format.h> +#include <AK/RefPtr.h> namespace PDF { @@ -66,7 +67,6 @@ public: : m_type(obj ? Type::Object : Type::Empty) { if (obj) { - obj->ref(); m_as_object = obj; } } @@ -75,7 +75,6 @@ public: Value(NonnullRefPtr<T> obj) : m_type(Type::Object) { - obj->ref(); m_as_object = obj; } @@ -84,7 +83,7 @@ public: *this = other; } - ~Value(); + ~Value() = default; Value& operator=(Value const& other); @@ -179,9 +178,9 @@ private: int m_as_int; u32 m_as_ref; float m_as_float; - Object* m_as_object; }; + RefPtr<Object> m_as_object; Type m_type; }; |