mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 09:30:24 +00:00
LibPDF: Convert PDF::Parser::m_document
from RefPtr
to WeakPtr
Otherwise both `PDF::Document` and `PDF::Parser` have a `RefPtr` pointing to each other which leads to a memory leak due to a circular dependency.
This commit is contained in:
parent
d8013f9c3a
commit
c857b5d22f
Notes:
sideshowbarker
2024-07-17 21:25:06 +09:00
Author: https://github.com/swoertz Commit: https://github.com/SerenityOS/serenity/commit/c857b5d22f7 Pull-request: https://github.com/SerenityOS/serenity/pull/10969 Issue: https://github.com/SerenityOS/serenity/issues/8215 Reviewed-by: https://github.com/ADKaster Reviewed-by: https://github.com/BenWiederhake Reviewed-by: https://github.com/bcoles Reviewed-by: https://github.com/linusg
3 changed files with 8 additions and 4 deletions
|
@ -9,6 +9,7 @@
|
|||
#include <AK/Format.h>
|
||||
#include <AK/HashMap.h>
|
||||
#include <AK/RefCounted.h>
|
||||
#include <AK/Weakable.h>
|
||||
#include <LibGfx/Color.h>
|
||||
#include <LibPDF/ObjectDerivatives.h>
|
||||
#include <LibPDF/Parser.h>
|
||||
|
@ -70,7 +71,9 @@ struct OutlineDict final : public RefCounted<OutlineDict> {
|
|||
OutlineDict() = default;
|
||||
};
|
||||
|
||||
class Document final : public RefCounted<Document> {
|
||||
class Document final
|
||||
: public RefCounted<Document>
|
||||
, public Weakable<Document> {
|
||||
public:
|
||||
static RefPtr<Document> create(ReadonlyBytes bytes);
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ Parser::Parser(ReadonlyBytes bytes)
|
|||
{
|
||||
}
|
||||
|
||||
void Parser::set_document(RefPtr<Document> const& document)
|
||||
void Parser::set_document(WeakPtr<Document> const& document)
|
||||
{
|
||||
m_document = document;
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/NonnullRefPtrVector.h>
|
||||
#include <AK/WeakPtr.h>
|
||||
#include <LibPDF/Command.h>
|
||||
#include <LibPDF/Object.h>
|
||||
#include <LibPDF/Reader.h>
|
||||
|
@ -29,7 +30,7 @@ public:
|
|||
Parser(Badge<Document>, ReadonlyBytes);
|
||||
|
||||
[[nodiscard]] ALWAYS_INLINE RefPtr<DictObject> const& trailer() const { return m_trailer; }
|
||||
void set_document(RefPtr<Document> const&);
|
||||
void set_document(WeakPtr<Document> const&);
|
||||
|
||||
// Parses the header and initializes the xref table and trailer
|
||||
bool initialize();
|
||||
|
@ -139,7 +140,7 @@ private:
|
|||
bool consume(char);
|
||||
|
||||
Reader m_reader;
|
||||
RefPtr<Document> m_document;
|
||||
WeakPtr<Document> m_document;
|
||||
RefPtr<XRefTable> m_xref_table;
|
||||
RefPtr<DictObject> m_trailer;
|
||||
Optional<LinearizationDictionary> m_linearization_dictionary;
|
||||
|
|
Loading…
Reference in a new issue