From b42493fb4c40611020c9ded9b7af5b96dc4148bd Mon Sep 17 00:00:00 2001 From: DS Date: Tue, 10 Mar 2020 20:32:38 +0100 Subject: [PATCH] Fix memory leak in GUIHyperText (#9489) --- src/gui/guiFormSpecMenu.cpp | 5 +++-- src/gui/guiHyperText.cpp | 6 +++--- src/gui/guiHyperText.h | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/gui/guiFormSpecMenu.cpp b/src/gui/guiFormSpecMenu.cpp index e1bb58f17..45eb0d17c 100644 --- a/src/gui/guiFormSpecMenu.cpp +++ b/src/gui/guiFormSpecMenu.cpp @@ -1654,8 +1654,9 @@ void GUIFormSpecMenu::parseHyperText(parserData *data, const std::string &elemen ); spec.ftype = f_Unknown; - new GUIHyperText( - spec.flabel.c_str(), Environment, this, spec.fid, rect, m_client, m_tsrc); + GUIHyperText *e = new GUIHyperText(spec.flabel.c_str(), Environment, this, + spec.fid, rect, m_client, m_tsrc); + e->drop(); m_fields.push_back(spec); } diff --git a/src/gui/guiHyperText.cpp b/src/gui/guiHyperText.cpp index 7b7d3a1b2..68fb8ea3d 100644 --- a/src/gui/guiHyperText.cpp +++ b/src/gui/guiHyperText.cpp @@ -109,7 +109,6 @@ ParsedText::ParsedText(const wchar_t *text) m_root_tag.style["color"] = "#EEEEEE"; m_root_tag.style["hovercolor"] = m_root_tag.style["color"]; - m_tags.push_back(&m_root_tag); m_active_tags.push_front(&m_root_tag); m_style = m_root_tag.style; @@ -174,7 +173,7 @@ ParsedText::ParsedText(const wchar_t *text) ParsedText::~ParsedText() { - for (auto &tag : m_tags) + for (auto &tag : m_not_root_tags) delete tag; } @@ -289,7 +288,7 @@ ParsedText::Tag *ParsedText::newTag(const std::string &name, const AttrsList &at Tag *newtag = new Tag(); newtag->name = name; newtag->attrs = attrs; - m_tags.push_back(newtag); + m_not_root_tags.push_back(newtag); return newtag; } @@ -1012,6 +1011,7 @@ GUIHyperText::GUIHyperText(const wchar_t *text, IGUIEnvironment *environment, GUIHyperText::~GUIHyperText() { m_vscrollbar->remove(); + m_vscrollbar->drop(); } ParsedText::Element *GUIHyperText::getElementAt(s32 X, s32 Y) diff --git a/src/gui/guiHyperText.h b/src/gui/guiHyperText.h index 3ea8732cd..093c84ccd 100644 --- a/src/gui/guiHyperText.h +++ b/src/gui/guiHyperText.h @@ -153,7 +153,7 @@ protected: std::unordered_map m_elementtags; std::unordered_map m_paragraphtags; - std::vector m_tags; + std::vector m_not_root_tags; std::list m_active_tags; // Current values -- 2.25.1