Repository: godot
Issue: Memory leak(~180KB) in EditorHelpSearch::Runner
Labels: bug,topic:editor,confirmed

**Godot version:**
3.2.dev.custom_build.15425b450

**OS/device including version:**
Ubuntu 19.04

**Issue description:**
When I opened and search some things in editor help search, and also change viewport from 2D, 3D to Script Editor, then this errors in Valgrind shows:
```
Invalid read of size 8
   at 0x2B33F7E: Tree::create_item(TreeItem*, int) (tree.cpp:3036)
   by 0x279CB9E: EditorHelpSearch::Runner::_create_class_item(TreeItem*, DocData::ClassDoc const*, bool) (editor_help_search.cpp:478)
   by 0x279C8A0: EditorHelpSearch::Runner::_create_class_hierarchy(EditorHelpSearch::Runner::ClassMatch const&) (editor_help_search.cpp:464)
   by 0x279C342: EditorHelpSearch::Runner::_phase_class_items() (editor_help_search.cpp:383)
   by 0x279B5CE: EditorHelpSearch::Runner::_slice() (editor_help_search.cpp:286)
   by 0x279E764: EditorHelpSearch::Runner::work(unsigned long) (editor_help_search.cpp:579)
   by 0x2799774: EditorHelpSearch::_notification(int) (editor_help_search.cpp:125)
   by 0x279F219: EditorHelpSearch::_notificationv(int, bool) (editor_help_search.h:42)
   by 0x3687F79: Object::notification(int, bool) (object.cpp:950)
   by 0x2907118: SceneTree::_notify_group_pause(StringName const&, int) (scene_tree.cpp:975)
   by 0x2904CFD: SceneTree::idle(float) (scene_tree.cpp:522)
   by 0x13C55F2: Main::iteration() (main.cpp:1919)
 Address 0x36457248 is 296 bytes inside a block of size 312 free'd
   at 0x584697B: free (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
   by 0x37C3642: Memory::free_static(void*, bool) (memory.cpp:181)
   by 0x1694759: void memdelete<TreeItem>(TreeItem*) (memory.h:122)
   by 0x2B2274A: TreeItem::clear_children() (tree.cpp:827)
   by 0x2B2286F: TreeItem::~TreeItem() (tree.cpp:847)
   by 0x1694748: void memdelete<TreeItem>(TreeItem*) (memory.h:120)
   by 0x2B2274A: TreeItem::clear_children() (tree.cpp:827)
   by 0x2B2286F: TreeItem::~TreeItem() (tree.cpp:847)
   by 0x1694748: void memdelete<TreeItem>(TreeItem*) (memory.h:120)
   by 0x2B2274A: TreeItem::clear_children() (tree.cpp:827)
   by 0x2B2286F: TreeItem::~TreeItem() (tree.cpp:847)
   by 0x1694748: void memdelete<TreeItem>(TreeItem*) (memory.h:120)
 Block was alloc'd at
   at 0x584574F: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
   by 0x37C3259: Memory::alloc_static(unsigned long, bool) (memory.cpp:85)
   by 0x37C3202: operator new(unsigned long, char const*) (memory.cpp:42)
   by 0x2B33EDA: Tree::create_item(TreeItem*, int) (tree.cpp:3031)
   by 0x279CB9E: EditorHelpSearch::Runner::_create_class_item(TreeItem*, DocData::ClassDoc const*, bool) (editor_help_search.cpp:478)
   by 0x279C8A0: EditorHelpSearch::Runner::_create_class_hierarchy(EditorHelpSearch::Runner::ClassMatch const&) (editor_help_search.cpp:464)
   by 0x279C877: EditorHelpSearch::Runner::_create_class_hierarchy(EditorHelpSearch::Runner::ClassMatch const&) (editor_help_search.cpp:460)
   by 0x279C342: EditorHelpSearch::Runner::_phase_class_items() (editor_help_search.cpp:383)
   by 0x279B5CE: EditorHelpSearch::Runner::_slice() (editor_help_search.cpp:286)
   by 0x279E764: EditorHelpSearch::Runner::work(unsigned long) (editor_help_search.cpp:579)
   by 0x2799774: EditorHelpSearch::_notification(int) (editor_help_search.cpp:125)
   by 0x279F219: EditorHelpSearch::_notificationv(int, bool) (editor_help_search.h:42)

Invalid write of size 8
   at 0x2B33FF4: Tree::create_item(TreeItem*, int) (tree.cpp:3051)
   by 0x279CB9E: EditorHelpSearch::Runner::_create_class_item(TreeItem*, DocData::ClassDoc const*, bool) (editor_help_search.cpp:478)
   by 0x279C8A0: EditorHelpSearch::Runner::_create_class_hierarchy(EditorHelpSearch::Runner::ClassMatch const&) (editor_help_search.cpp:464)
   by 0x279C342: EditorHelpSearch::Runner::_phase_class_items() (editor_help_search.cpp:383)
   by 0x279B5CE: EditorHelpSearch::Runner::_slice() (editor_help_search.cpp:286)
   by 0x279E764: EditorHelpSearch::Runner::work(unsigned long) (editor_help_search.cpp:579)
   by 0x2799774: EditorHelpSearch::_notification(int) (editor_help_search.cpp:125)
   by 0x279F219: EditorHelpSearch::_notificationv(int, bool) (editor_help_search.h:42)
   by 0x3687F79: Object::notification(int, bool) (object.cpp:950)
   by 0x2907118: SceneTree::_notify_group_pause(StringName const&, int) (scene_tree.cpp:975)
   by 0x2904CFD: SceneTree::idle(float) (scene_tree.cpp:522)
   by 0x13C55F2: Main::iteration() (main.cpp:1919)
 Address 0x36457248 is 296 bytes inside a block of size 312 free'd
   at 0x584697B: free (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
   by 0x37C3642: Memory::free_static(void*, bool) (memory.cpp:181)
   by 0x1694759: void memdelete<TreeItem>(TreeItem*) (memory.h:122)
   by 0x2B2274A: TreeItem::clear_children() (tree.cpp:827)
   by 0x2B2286F: TreeItem::~TreeItem() (tree.cpp:847)
   by 0x1694748: void memdelete<TreeItem>(TreeItem*) (memory.h:120)
   by 0x2B2274A: TreeItem::clear_children() (tree.cpp:827)
   by 0x2B2286F: TreeItem::~TreeItem() (tree.cpp:847)
   by 0x1694748: void memdelete<TreeItem>(TreeItem*) (memory.h:120)
   by 0x2B2274A: TreeItem::clear_children() (tree.cpp:827)
   by 0x2B2286F: TreeItem::~TreeItem() (tree.cpp:847)
   by 0x1694748: void memdelete<TreeItem>(TreeItem*) (memory.h:120)
 Block was alloc'd at
   at 0x584574F: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
   by 0x37C3259: Memory::alloc_static(unsigned long, bool) (memory.cpp:85)
   by 0x37C3202: operator new(unsigned long, char const*) (memory.cpp:42)
   by 0x2B33EDA: Tree::create_item(TreeItem*, int) (tree.cpp:3031)
   by 0x279CB9E: EditorHelpSearch::Runner::_create_class_item(TreeItem*, DocData::ClassDoc const*, bool) (editor_help_search.cpp:478)
   by 0x279C8A0: EditorHelpSearch::Runner::_create_class_hierarchy(EditorHelpSearch::Runner::ClassMatch const&) (editor_help_search.cpp:464)
   by 0x279C877: EditorHelpSearch::Runner::_create_class_hierarchy(EditorHelpSearch::Runner::ClassMatch const&) (editor_help_search.cpp:460)
   by 0x279C342: EditorHelpSearch::Runner::_phase_class_items() (editor_help_search.cpp:383)
   by 0x279B5CE: EditorHelpSearch::Runner::_slice() (editor_help_search.cpp:286)
   by 0x279E764: EditorHelpSearch::Runner::work(unsigned long) (editor_help_search.cpp:579)
   by 0x2799774: EditorHelpSearch::_notification(int) (editor_help_search.cpp:125)
   by 0x279F219: EditorHelpSearch::_notificationv(int, bool) (editor_help_search.h:42)

Invalid read of size 8
   at 0x2B33F7E: Tree::create_item(TreeItem*, int) (tree.cpp:3036)
   by 0x279CB9E: EditorHelpSearch::Runner::_create_class_item(TreeItem*, DocData::ClassDoc const*, bool) (editor_help_search.cpp:478)
   by 0x279C8A0: EditorHelpSearch::Runner::_create_class_hierarchy(EditorHelpSearch::Runner::ClassMatch const&) (editor_help_search.cpp:464)
   by 0x279C877: EditorHelpSearch::Runner::_create_class_hierarchy(EditorHelpSearch::Runner::ClassMatch const&) (editor_help_search.cpp:460)
   by 0x279C342: EditorHelpSearch::Runner::_phase_class_items() (editor_help_search.cpp:383)
   by 0x279B5CE: EditorHelpSearch::Runner::_slice() (editor_help_search.cpp:286)
   by 0x279E764: EditorHelpSearch::Runner::work(unsigned long) (editor_help_search.cpp:579)
   by 0x2799774: EditorHelpSearch::_notification(int) (editor_help_search.cpp:125)
   by 0x279F219: EditorHelpSearch::_notificationv(int, bool) (editor_help_search.h:42)
   by 0x3687F79: Object::notification(int, bool) (object.cpp:950)
   by 0x2907118: SceneTree::_notify_group_pause(StringName const&, int) (scene_tree.cpp:975)
   by 0x2904CFD: SceneTree::idle(float) (scene_tree.cpp:522)
 Address 0x3778de68 is 296 bytes inside a block of size 312 free'd
   at 0x584697B: free (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
   by 0x37C3642: Memory::free_static(void*, bool) (memory.cpp:181)
   by 0x1694759: void memdelete<TreeItem>(TreeItem*) (memory.h:122)
   by 0x2B2274A: TreeItem::clear_children() (tree.cpp:827)
   by 0x2B2286F: TreeItem::~TreeItem() (tree.cpp:847)
   by 0x1694748: void memdelete<TreeItem>(TreeItem*) (memory.h:120)
   by 0x2B2274A: TreeItem::clear_children() (tree.cpp:827)
   by 0x2B2286F: TreeItem::~TreeItem() (tree.cpp:847)
   by 0x1694748: void memdelete<TreeItem>(TreeItem*) (memory.h:120)
   by 0x2B2274A: TreeItem::clear_children() (tree.cpp:827)
   by 0x2B2286F: TreeItem::~TreeItem() (tree.cpp:847)
   by 0x1694748: void memdelete<TreeItem>(TreeItem*) (memory.h:120)
 Block was alloc'd at
   at 0x584574F: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
   by 0x37C3259: Memory::alloc_static(unsigned long, bool) (memory.cpp:85)
   by 0x37C3202: operator new(unsigned long, char const*) (memory.cpp:42)
   by 0x2B33EDA: Tree::create_item(TreeItem*, int) (tree.cpp:3031)
   by 0x279CB9E: EditorHelpSearch::Runner::_create_class_item(TreeItem*, DocData::ClassDoc const*, bool) (editor_help_search.cpp:478)
   by 0x279C8A0: EditorHelpSearch::Runner::_create_class_hierarchy(EditorHelpSearch::Runner::ClassMatch const&) (editor_help_search.cpp:464)
   by 0x279C877: EditorHelpSearch::Runner::_create_class_hierarchy(EditorHelpSearch::Runner::ClassMatch const&) (editor_help_search.cpp:460)
   by 0x279C877: EditorHelpSearch::Runner::_create_class_hierarchy(EditorHelpSearch::Runner::ClassMatch const&) (editor_help_search.cpp:460)
   by 0x279C342: EditorHelpSearch::Runner::_phase_class_items() (editor_help_search.cpp:383)
   by 0x279B5CE: EditorHelpSearch::Runner::_slice() (editor_help_search.cpp:286)
   by 0x279E764: EditorHelpSearch::Runner::work(unsigned long) (editor_help_search.cpp:579)
   by 0x2799774: EditorHelpSearch::_notification(int) (editor_help_search.cpp:125)

Invalid write of size 8
   at 0x2B33FF4: Tree::create_item(TreeItem*, int) (tree.cpp:3051)
   by 0x279CB9E: EditorHelpSearch::Runner::_create_class_item(TreeItem*, DocData::ClassDoc const*, bool) (editor_help_search.cpp:478)
   by 0x279C8A0: EditorHelpSearch::Runner::_create_class_hierarchy(EditorHelpSearch::Runner::ClassMatch const&) (editor_help_search.cpp:464)
   by 0x279C877: EditorHelpSearch::Runner::_create_class_hierarchy(EditorHelpSearch::Runner::ClassMatch const&) (editor_help_search.cpp:460)
   by 0x279C342: EditorHelpSearch::Runner::_phase_class_items() (editor_help_search.cpp:383)
   by 0x279B5CE: EditorHelpSearch::Runner::_slice() (editor_help_search.cpp:286)
   by 0x279E764: EditorHelpSearch::Runner::work(unsigned long) (editor_help_search.cpp:579)
   by 0x2799774: EditorHelpSearch::_notification(int) (editor_help_search.cpp:125)
   by 0x279F219: EditorHelpSearch::_notificationv(int, bool) (editor_help_search.h:42)
   by 0x3687F79: Object::notification(int, bool) (object.cpp:950)
   by 0x2907118: SceneTree::_notify_group_pause(StringName const&, int) (scene_tree.cpp:975)
   by 0x2904CFD: SceneTree::idle(float) (scene_tree.cpp:522)
 Address 0x3778de68 is 296 bytes inside a block of size 312 free'd
   at 0x584697B: free (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
   by 0x37C3642: Memory::free_static(void*, bool) (memory.cpp:181)
   by 0x1694759: void memdelete<TreeItem>(TreeItem*) (memory.h:122)
   by 0x2B2274A: TreeItem::clear_children() (tree.cpp:827)
   by 0x2B2286F: TreeItem::~TreeItem() (tree.cpp:847)
   by 0x1694748: void memdelete<TreeItem>(TreeItem*) (memory.h:120)
   by 0x2B2274A: TreeItem::clear_children() (tree.cpp:827)
   by 0x2B2286F: TreeItem::~TreeItem() (tree.cpp:847)
   by 0x1694748: void memdelete<TreeItem>(TreeItem*) (memory.h:120)
   by 0x2B2274A: TreeItem::clear_children() (tree.cpp:827)
   by 0x2B2286F: TreeItem::~TreeItem() (tree.cpp:847)
   by 0x1694748: void memdelete<TreeItem>(TreeItem*) (memory.h:120)
 Block was alloc'd at
   at 0x584574F: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
   by 0x37C3259: Memory::alloc_static(unsigned long, bool) (memory.cpp:85)
   by 0x37C3202: operator new(unsigned long, char const*) (memory.cpp:42)
   by 0x2B33EDA: Tree::create_item(TreeItem*, int) (tree.cpp:3031)
   by 0x279CB9E: EditorHelpSearch::Runner::_create_class_item(TreeItem*, DocData::ClassDoc const*, bool) (editor_help_search.cpp:478)
   by 0x279C8A0: EditorHelpSearch::Runner::_create_class_hierarchy(EditorHelpSearch::Runner::ClassMatch const&) (editor_help_search.cpp:464)
   by 0x279C877: EditorHelpSearch::Runner::_create_class_hierarchy(EditorHelpSearch::Runner::ClassMatch const&) (editor_help_search.cpp:460)
   by 0x279C877: EditorHelpSearch::Runner::_create_class_hierarchy(EditorHelpSearch::Runner::ClassMatch const&) (editor_help_search.cpp:460)
   by 0x279C342: EditorHelpSearch::Runner::_phase_class_items() (editor_help_search.cpp:383)
   by 0x279B5CE: EditorHelpSearch::Runner::_slice() (editor_help_search.cpp:286)
   by 0x279E764: EditorHelpSearch::Runner::work(unsigned long) (editor_help_search.cpp:579)
   by 0x2799774: EditorHelpSearch::_notification(int) (editor_help_search.cpp:125)

Leaked instance: ImageTexture:2077 - Resource name:  Path: 
Leaked instance: TreeItem:27291
Leaked instance: TreeItem:27330
Leaked instance: TreeItem:27195
Leaked instance: TreeItem:27275
Leaked instance: TreeItem:27337
Leaked instance: TreeItem:27237
Leaked instance: TreeItem:27329
Leaked instance: TreeItem:27226
Leaked instance: TreeItem:27338
Leaked instance: TreeItem:27230
Leaked instance: TreeItem:27219
Leaked instance: Image:2536 - Resource name:  Path: 
Leaked instance: TreeItem:27241
Orphan StringName: ImageTexture
Orphan StringName: TreeItem
Orphan StringName: Image


10,672 bytes in 11 blocks are definitely lost in loss record 284 of 288
   at 0x584574F: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
   by 0x37C3259: Memory::alloc_static(unsigned long, bool) (memory.cpp:85)
   by 0x13EAB18: PoolVector<unsigned char>::resize(int) (pool_vector.h:577)
   by 0x36440A1: Image::shrink_x2() (image.cpp:1393)
   by 0x18FB537: ImageLoaderSVG::_create_image(Ref<Image>, PoolVector<unsigned char> const*, float, bool, bool) (image_loader_svg.cpp:129)
   by 0x18FB809: ImageLoaderSVG::create_image_from_string(Ref<Image>, char const*, float, bool, bool) (image_loader_svg.cpp:144)
   by 0x20FB8BB: editor_generate_icon(int, bool, float, bool) (editor_themes.cpp:92)
   by 0x20FEB0E: editor_register_and_generate_icons(Ref<Theme>, bool, int, bool) (editor_themes.cpp:202)
   by 0x2102380: create_editor_theme(Ref<Theme>) (editor_themes.cpp:386)
   by 0x211C618: create_custom_theme(Ref<Theme>) (editor_themes.cpp:1180)
   by 0x202790A: EditorNode::EditorNode() (editor_node.cpp:5450)
   by 0x13C1FE4: Main::start() (main.cpp:1614)

178,688 (3,432 direct, 175,256 indirect) bytes in 11 blocks are definitely lost in loss record 288 of 288
   at 0x584574F: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
   by 0x37C3259: Memory::alloc_static(unsigned long, bool) (memory.cpp:85)
   by 0x37C3202: operator new(unsigned long, char const*) (memory.cpp:42)
   by 0x2B33EDA: Tree::create_item(TreeItem*, int) (tree.cpp:3031)
   by 0x279CB9E: EditorHelpSearch::Runner::_create_class_item(TreeItem*, DocData::ClassDoc const*, bool) (editor_help_search.cpp:478)
   by 0x279C8A0: EditorHelpSearch::Runner::_create_class_hierarchy(EditorHelpSearch::Runner::ClassMatch const&) (editor_help_search.cpp:464)
   by 0x279C342: EditorHelpSearch::Runner::_phase_class_items() (editor_help_search.cpp:383)
   by 0x279B5CE: EditorHelpSearch::Runner::_slice() (editor_help_search.cpp:286)
   by 0x279E764: EditorHelpSearch::Runner::work(unsigned long) (editor_help_search.cpp:579)
   by 0x2799774: EditorHelpSearch::_notification(int) (editor_help_search.cpp:125)
   by 0x279F219: EditorHelpSearch::_notificationv(int, bool) (editor_help_search.h:42)
   by 0x3687F79: Object::notification(int, bool) (object.cpp:950)
```

I think that this is very similar issue as #29215

**Minimal project**:
This should happens with empty project