mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 10:57:34 +00:00
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.
This commit is contained in:
parent
05006e63c4
commit
750bed254f
2 changed files with 3 additions and 12 deletions
|
@ -9,12 +9,6 @@
|
||||||
|
|
||||||
namespace PDF {
|
namespace PDF {
|
||||||
|
|
||||||
Value::~Value()
|
|
||||||
{
|
|
||||||
if (is_object())
|
|
||||||
m_as_object->unref();
|
|
||||||
}
|
|
||||||
|
|
||||||
Value& Value::operator=(Value const& other)
|
Value& Value::operator=(Value const& other)
|
||||||
{
|
{
|
||||||
m_type = other.m_type;
|
m_type = other.m_type;
|
||||||
|
@ -36,8 +30,6 @@ Value& Value::operator=(Value const& other)
|
||||||
break;
|
break;
|
||||||
case Type::Object:
|
case Type::Object:
|
||||||
m_as_object = other.m_as_object;
|
m_as_object = other.m_as_object;
|
||||||
if (m_as_object)
|
|
||||||
m_as_object->ref();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/Format.h>
|
#include <AK/Format.h>
|
||||||
|
#include <AK/RefPtr.h>
|
||||||
|
|
||||||
namespace PDF {
|
namespace PDF {
|
||||||
|
|
||||||
|
@ -66,7 +67,6 @@ public:
|
||||||
: m_type(obj ? Type::Object : Type::Empty)
|
: m_type(obj ? Type::Object : Type::Empty)
|
||||||
{
|
{
|
||||||
if (obj) {
|
if (obj) {
|
||||||
obj->ref();
|
|
||||||
m_as_object = obj;
|
m_as_object = obj;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,6 @@ public:
|
||||||
Value(NonnullRefPtr<T> obj)
|
Value(NonnullRefPtr<T> obj)
|
||||||
: m_type(Type::Object)
|
: m_type(Type::Object)
|
||||||
{
|
{
|
||||||
obj->ref();
|
|
||||||
m_as_object = obj;
|
m_as_object = obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,7 +83,7 @@ public:
|
||||||
*this = other;
|
*this = other;
|
||||||
}
|
}
|
||||||
|
|
||||||
~Value();
|
~Value() = default;
|
||||||
|
|
||||||
Value& operator=(Value const& other);
|
Value& operator=(Value const& other);
|
||||||
|
|
||||||
|
@ -179,9 +178,9 @@ private:
|
||||||
int m_as_int;
|
int m_as_int;
|
||||||
u32 m_as_ref;
|
u32 m_as_ref;
|
||||||
float m_as_float;
|
float m_as_float;
|
||||||
Object* m_as_object;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
RefPtr<Object> m_as_object;
|
||||||
Type m_type;
|
Type m_type;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue