From fbe02c5ae102b0bf048c5e8265b8c5a60c0bd17c Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sun, 16 Aug 2020 13:18:40 +0300 Subject: [PATCH] tests/valgrind: add skipped fn_with_return_should_free_local_vars.vv (-autofree) --- .../fn_with_return_should_free_local_vars.vv | 20 +++++++++++++++++++ vlib/v/tests/valgrind/valgrind_test.v | 1 + 2 files changed, 21 insertions(+) create mode 100644 vlib/v/tests/valgrind/fn_with_return_should_free_local_vars.vv diff --git a/vlib/v/tests/valgrind/fn_with_return_should_free_local_vars.vv b/vlib/v/tests/valgrind/fn_with_return_should_free_local_vars.vv new file mode 100644 index 0000000000..669371c908 --- /dev/null +++ b/vlib/v/tests/valgrind/fn_with_return_should_free_local_vars.vv @@ -0,0 +1,20 @@ +fn many_strings() []string { + mut res := []string{} + for i in 0..10000 { res << '${i:05}' } + return res +} + +fn abc() int { + x := many_strings() + n := x.len + // NB: the local `x` is no longer used + // it should be freed *before* the return + return n +} + +fn main() { + for i in 0..5 { + nstrings := abc() + eprintln('nstrings ${i:10}: $nstrings') + } +} diff --git a/vlib/v/tests/valgrind/valgrind_test.v b/vlib/v/tests/valgrind/valgrind_test.v index 1865d942cb..2d5c89f568 100644 --- a/vlib/v/tests/valgrind/valgrind_test.v +++ b/vlib/v/tests/valgrind/valgrind_test.v @@ -8,6 +8,7 @@ const ( skip_valgrind_files = [ 'vlib/v/tests/valgrind/struct_field.vv', 'vlib/v/tests/valgrind/fn_returning_string_param.vv', + 'vlib/v/tests/valgrind/fn_with_return_should_free_local_vars.vv', ] )