Merge pull request #30823 from Paulb23/issue_29500_syntax_highlighter_leak

Fix memory leaks with SyntaxHighlighters
This commit is contained in:
Rémi Verschelde 2019-07-25 23:12:35 +02:00 committed by GitHub
commit b6ab5b5e2b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 31 additions and 9 deletions

View File

@ -2088,6 +2088,7 @@ bool ScriptEditor::edit(const RES &p_resource, int p_line, int p_col, bool p_gra
}
ERR_FAIL_COND_V(!se, false);
if (p_resource->get_class_name() != StringName("VisualScript")) {
bool highlighter_set = false;
for (int i = 0; i < syntax_highlighters_func_count; i++) {
SyntaxHighlighter *highlighter = syntax_highlighters_funcs[i]();
@ -2101,6 +2102,7 @@ bool ScriptEditor::edit(const RES &p_resource, int p_line, int p_col, bool p_gra
}
}
}
}
tab_container->add_child(se);
se->set_edited_resource(p_resource);

View File

@ -1819,6 +1819,15 @@ ScriptTextEditor::ScriptTextEditor() {
code_editor->get_text_edit()->set_drag_forwarding(this);
}
ScriptTextEditor::~ScriptTextEditor() {
for (const Map<String, SyntaxHighlighter *>::Element *E = highlighters.front(); E; E = E->next()) {
if (E->get() != NULL) {
memdelete(E->get());
}
}
highlighters.clear();
}
static ScriptEditorBase *create_editor(const RES &p_resource) {
if (Object::cast_to<Script>(*p_resource)) {

View File

@ -231,6 +231,7 @@ public:
virtual void validate();
ScriptTextEditor();
~ScriptTextEditor();
};
#endif // SCRIPT_TEXT_EDITOR_H

View File

@ -695,5 +695,14 @@ TextEditor::TextEditor() {
code_editor->get_text_edit()->set_drag_forwarding(this);
}
TextEditor::~TextEditor() {
for (const Map<String, SyntaxHighlighter *>::Element *E = highlighters.front(); E; E = E->next()) {
if (E->get() != NULL) {
memdelete(E->get());
}
}
highlighters.clear();
}
void TextEditor::validate() {
}

View File

@ -154,6 +154,7 @@ public:
static void register_editor();
TextEditor();
~TextEditor();
};
#endif // TEXT_EDITOR_H