diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index 409e7699b8..b66efc1129 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -512,6 +512,12 @@ fn (g mut Gen) gen_assign_stmt(assign_stmt ast.AssignStmt) { g.expr(val) g.write(')') } + else if g.autofree && right_sym.kind == .string && is_ident { + // `str1 = str2` => `str1 = str2.clone()` + g.write(' = string_clone(') + g.expr(val) + g.write(')') + } else if !is_fixed_array_init { g.write(' = ') if !is_decl { diff --git a/vlib/v/tests/valgrind/1.vv b/vlib/v/tests/valgrind/1.vv index c90973b34e..c4e73b9a14 100644 --- a/vlib/v/tests/valgrind/1.vv +++ b/vlib/v/tests/valgrind/1.vv @@ -10,7 +10,7 @@ fn foo() { nums_copy := nums // array assignments call .clone() println(nums) println(nums_copy) - nums.free() + // nums.free() // this should result in a double free and a CI error } fn main() {