Repository: godot
Issue: Invalid  read in audio demo
Labels: bug,topic:audio

**Godot version:**
Godot 3.2 beta 4
**OS/device including version:**
Ubuntu 19.10
**Issue description:**
Sanitizer Log(asan)
```
==7635==ERROR: AddressSanitizer: heap-use-after-free on address 0x631006a5480c at pc 0x00000163132e bp 0x7ffc6bce04d0 sp 0x7ffc6bce04c0
READ of size 4 at 0x631006a5480c thread T0
    #0 0x163132d in CowData<float>::size() const core/cowdata.h:128
    #1 0x16317bc in CowData<float>::get(int) const core/cowdata.h:152
    #2 0x162d8cf in Vector<float>::operator[](int) const core/vector.h:85
    #3 0xda3dbef in AudioEffectRecord::get_recording() const servers/audio/effects/audio_effect_record.cpp:238
    #4 0xda4d2d4 in MethodBind0RC<Ref<AudioStreamSample> >::call(Object*, Variant const**, int, Variant::CallError&) core/method_bind.gen.inc:593
    #5 0xe52a5cc in Object::call(StringName const&, Variant const**, int, Variant::CallError&) core/object.cpp:921
    #6 0xe79d090 in Variant::call_ptr(StringName const&, Variant const**, int, Variant*, Variant::CallError&) core/variant_call.cpp:1112
    #7 0x1a182e9 in GDScriptFunction::call(GDScriptInstance*, Variant const**, int, Variant::CallError&, GDScriptFunction::CallState*) modules/gdscript/gdscript_function.cpp:1078
    #8 0x18549c3 in GDScriptInstance::call(StringName const&, Variant const**, int, Variant::CallError&) modules/gdscript/gdscript.cpp:1173
    #9 0xe52a139 in Object::call(StringName const&, Variant const**, int, Variant::CallError&) core/object.cpp:900
    #10 0xe533fc4 in Object::emit_signal(StringName const&, Variant const**, int) core/object.cpp:1219
    #11 0xe535f8b in Object::emit_signal(StringName const&, Variant const&, Variant const&, Variant const&, Variant const&, Variant const&) core/object.cpp:1276
    #12 0x960abeb in BaseButton::_pressed() scene/gui/base_button.cpp:135
    #13 0x960e558 in BaseButton::on_action_event(Ref<InputEvent>) scene/gui/base_button.cpp:169
    #14 0x96074c5 in BaseButton::_gui_input(Ref<InputEvent>) scene/gui/base_button.cpp:64
    #15 0x647ce71 in MethodBind1<Ref<InputEvent> >::call(Object*, Variant const**, int, Variant::CallError&) core/method_bind.gen.inc:775
    #16 0xe5261e0 in Object::call_multilevel(StringName const&, Variant const**, int) core/object.cpp:763
    #17 0xe5292eb in Object::call_multilevel(StringName const&, Variant const&, Variant const&, Variant const&, Variant const&, Variant const&) core/object.cpp:863
    #18 0x950d202 in Viewport::_gui_call_input(Control*, Ref<InputEvent> const&) scene/main/viewport.cpp:1634
    #19 0x951c9f5 in Viewport::_gui_input_event(Ref<InputEvent>) scene/main/viewport.cpp:2014
    #20 0x9540d8d in Viewport::input(Ref<InputEvent> const&) scene/main/viewport.cpp:2790
    #21 0x9500b3a in Viewport::_vp_input(Ref<InputEvent> const&) scene/main/viewport.cpp:1411
    #22 0x234cd1d in MethodBind1<Ref<InputEvent> const&>::call(Object*, Variant const**, int, Variant::CallError&) core/method_bind.gen.inc:775
    #23 0xe52a5cc in Object::call(StringName const&, Variant const**, int, Variant::CallError&) core/object.cpp:921
    #24 0xe528d1d in Object::call(StringName const&, Variant const&, Variant const&, Variant const&, Variant const&, Variant const&) core/object.cpp:847
    #25 0x93efa59 in SceneTree::call_group_flags(unsigned int, StringName const&, StringName const&, Variant const&, Variant const&, Variant const&, Variant const&, Variant const&) scene/main/scene_tree.cpp:275
    #26 0x93f4ee4 in SceneTree::input_event(Ref<InputEvent> const&) scene/main/scene_tree.cpp:430
    #27 0x14e98d8 in InputDefault::_parse_input_event_impl(Ref<InputEvent> const&, bool) main/input_default.cpp:442
    #28 0x14deee6 in InputDefault::parse_input_event(Ref<InputEvent> const&) main/input_default.cpp:259
    #29 0x14f1ec4 in InputDefault::flush_accumulated_events() main/input_default.cpp:678
    #30 0x147077d in OS_X11::process_xevents() platform/x11/os_x11.cpp:2687
    #31 0x1482ed2 in OS_X11::run() platform/x11/os_x11.cpp:3251
    #32 0x13fe299 in main platform/x11/godot_x11.cpp:56
    #33 0x7fd3a1bfe1e2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x271e2)
    #34 0x13fdead in _start (/usr/bin/godots+0x13fdead)

0x631006a5480c is located 12 bytes inside of 65552-byte region [0x631006a54800,0x631006a64810)
freed by thread T5 here:
    #0 0x7fd3a3122f1e in __interceptor_realloc (/lib/x86_64-linux-gnu/libasan.so.5+0x10df1e)
    #1 0xea53d97 in Memory::realloc_static(void*, unsigned long, bool) core/os/memory.cpp:137
    #2 0x1630ebe in CowData<float>::resize(int) (/usr/bin/godots+0x1630ebe)
    #3 0x162d2e8 in Vector<float>::resize(int) core/vector.h:84
    #4 0x2b77d35 in Vector<float>::push_back(float const&) core/vector.h:152
    #5 0xda394e5 in AudioEffectRecordInstance::_io_store_buffer() servers/audio/effects/audio_effect_record.cpp:95
    #6 0xda37e33 in AudioEffectRecordInstance::_update_buffer() servers/audio/effects/audio_effect_record.cpp:55
    #7 0xda3868c in AudioEffectRecordInstance::_io_thread_process() servers/audio/effects/audio_effect_record.cpp:77
    #8 0xda39918 in AudioEffectRecordInstance::_thread_callback(void*) servers/audio/effects/audio_effect_record.cpp:107
    #9 0x4f821a5 in ThreadPosix::thread_callback(void*) drivers/unix/thread_posix.cpp:74
    #10 0x7fd3a2a98668 in start_thread /build/glibc-4WA41p/glibc-2.30/nptl/pthread_create.c:479

previously allocated by thread T5 here:
    #0 0x7fd3a3122f1e in __interceptor_realloc (/lib/x86_64-linux-gnu/libasan.so.5+0x10df1e)
    #1 0xea53d97 in Memory::realloc_static(void*, unsigned long, bool) core/os/memory.cpp:137
    #2 0x1630ebe in CowData<float>::resize(int) (/usr/bin/godots+0x1630ebe)
    #3 0x162d2e8 in Vector<float>::resize(int) core/vector.h:84
    #4 0x2b77d35 in Vector<float>::push_back(float const&) core/vector.h:152
    #5 0xda3957f in AudioEffectRecordInstance::_io_store_buffer() servers/audio/effects/audio_effect_record.cpp:96
    #6 0xda37e33 in AudioEffectRecordInstance::_update_buffer() servers/audio/effects/audio_effect_record.cpp:55
    #7 0xda3868c in AudioEffectRecordInstance::_io_thread_process() servers/audio/effects/audio_effect_record.cpp:77
    #8 0xda39918 in AudioEffectRecordInstance::_thread_callback(void*) servers/audio/effects/audio_effect_record.cpp:107
    #9 0x4f821a5 in ThreadPosix::thread_callback(void*) drivers/unix/thread_posix.cpp:74
    #10 0x7fd3a2a98668 in start_thread /build/glibc-4WA41p/glibc-2.30/nptl/pthread_create.c:479

Thread T5 created by T0 here:
    #0 0x7fd3a304f805 in pthread_create (/lib/x86_64-linux-gnu/libasan.so.5+0x3a805)
    #1 0x4f826a0 in ThreadPosix::create_func_posix(void (*)(void*), void*, Thread::Settings const&) drivers/unix/thread_posix.cpp:90
    #2 0xea676b1 in Thread::create(void (*)(void*), void*, Thread::Settings const&) core/os/thread.cpp:51
    #3 0xda39fe8 in AudioEffectRecordInstance::init() servers/audio/effects/audio_effect_record.cpp:122
    #4 0xda3c21e in AudioEffectRecord::set_recording_active(bool) servers/audio/effects/audio_effect_record.cpp:196
    #5 0x1eaaf81 in MethodBind1<bool>::call(Object*, Variant const**, int, Variant::CallError&) core/method_bind.gen.inc:775
    #6 0xe52a5cc in Object::call(StringName const&, Variant const**, int, Variant::CallError&) core/object.cpp:921
    #7 0xe79d090 in Variant::call_ptr(StringName const&, Variant const**, int, Variant*, Variant::CallError&) core/variant_call.cpp:1112
    #8 0x1a1836a in GDScriptFunction::call(GDScriptInstance*, Variant const**, int, Variant::CallError&, GDScriptFunction::CallState*) modules/gdscript/gdscript_function.cpp:1081
    #9 0x18549c3 in GDScriptInstance::call(StringName const&, Variant const**, int, Variant::CallError&) modules/gdscript/gdscript.cpp:1173
    #10 0xe52a139 in Object::call(StringName const&, Variant const**, int, Variant::CallError&) core/object.cpp:900
    #11 0xe533fc4 in Object::emit_signal(StringName const&, Variant const**, int) core/object.cpp:1219
    #12 0xe535f8b in Object::emit_signal(StringName const&, Variant const&, Variant const&, Variant const&, Variant const&, Variant const&) core/object.cpp:1276
    #13 0x960abeb in BaseButton::_pressed() scene/gui/base_button.cpp:135
    #14 0x960e558 in BaseButton::on_action_event(Ref<InputEvent>) scene/gui/base_button.cpp:169
    #15 0x96074c5 in BaseButton::_gui_input(Ref<InputEvent>) scene/gui/base_button.cpp:64
    #16 0x647ce71 in MethodBind1<Ref<InputEvent> >::call(Object*, Variant const**, int, Variant::CallError&) core/method_bind.gen.inc:775
    #17 0xe5261e0 in Object::call_multilevel(StringName const&, Variant const**, int) core/object.cpp:763
    #18 0xe5292eb in Object::call_multilevel(StringName const&, Variant const&, Variant const&, Variant const&, Variant const&, Variant const&) core/object.cpp:863
    #19 0x950d202 in Viewport::_gui_call_input(Control*, Ref<InputEvent> const&) scene/main/viewport.cpp:1634
    #20 0x951c9f5 in Viewport::_gui_input_event(Ref<InputEvent>) scene/main/viewport.cpp:2014
    #21 0x9540d8d in Viewport::input(Ref<InputEvent> const&) scene/main/viewport.cpp:2790
    #22 0x9500b3a in Viewport::_vp_input(Ref<InputEvent> const&) scene/main/viewport.cpp:1411
    #23 0x234cd1d in MethodBind1<Ref<InputEvent> const&>::call(Object*, Variant const**, int, Variant::CallError&) core/method_bind.gen.inc:775
    #24 0xe52a5cc in Object::call(StringName const&, Variant const**, int, Variant::CallError&) core/object.cpp:921
    #25 0xe528d1d in Object::call(StringName const&, Variant const&, Variant const&, Variant const&, Variant const&, Variant const&) core/object.cpp:847
    #26 0x93efa59 in SceneTree::call_group_flags(unsigned int, StringName const&, StringName const&, Variant const&, Variant const&, Variant const&, Variant const&, Variant const&) scene/main/scene_tree.cpp:275
    #27 0x93f4ee4 in SceneTree::input_event(Ref<InputEvent> const&) scene/main/scene_tree.cpp:430
    #28 0x14e98d8 in InputDefault::_parse_input_event_impl(Ref<InputEvent> const&, bool) main/input_default.cpp:442
    #29 0x14deee6 in InputDefault::parse_input_event(Ref<InputEvent> const&) main/input_default.cpp:259
    #30 0x14f1ec4 in InputDefault::flush_accumulated_events() main/input_default.cpp:678
    #31 0x147077d in OS_X11::process_xevents() platform/x11/os_x11.cpp:2687
    #32 0x1482ed2 in OS_X11::run() platform/x11/os_x11.cpp:3251
    #33 0x13fe299 in main platform/x11/godot_x11.cpp:56
    #34 0x7fd3a1bfe1e2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x271e2)
```
**Steps to reproduce:**
1. Run project
2. Click "Record"
3. Click "Stop"
**Minimal reproduction project:**
https://github.com/godotengine/godot-demo-projects/tree/master/audio/mic_record