From 6444f49d22dc1f173ebe5a0cf5862f0f3338b916 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 16 Aug 2020 20:31:05 +0200 Subject: [PATCH] LibJS: Make StringOrSymbol not leak strings Ideally this thing would not allocate strings at all, but I'll leave that as a separate exercise. --- Libraries/LibJS/Runtime/StringOrSymbol.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Libraries/LibJS/Runtime/StringOrSymbol.h b/Libraries/LibJS/Runtime/StringOrSymbol.h index a0b7cacebf..2ebc189023 100644 --- a/Libraries/LibJS/Runtime/StringOrSymbol.h +++ b/Libraries/LibJS/Runtime/StringOrSymbol.h @@ -55,6 +55,12 @@ public: { } + ~StringOrSymbol() + { + if (is_string()) + reinterpret_cast(m_ptr)->unref(); + } + StringOrSymbol(const Symbol* symbol) : m_ptr(symbol) { @@ -64,6 +70,8 @@ public: StringOrSymbol(const StringOrSymbol& other) { m_ptr = other.m_ptr; + if (is_string()) + reinterpret_cast(m_ptr)->ref(); } ALWAYS_INLINE bool is_valid() const { return m_ptr != nullptr; } @@ -120,6 +128,8 @@ public: if (this == &other) return *this; m_ptr = other.m_ptr; + if (is_string()) + reinterpret_cast(m_ptr)->ref(); return *this; }