Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

str_intp: autofree memory leak fix 1 #23549

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions vlib/v/gen/c/str_intp.v
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,14 @@ fn (mut g Gen) string_inter_literal(node ast.StringInterLiteral) {
}
}
}

mut tmp_var := ''
mut curr_line := ''
if g.is_autofree {
curr_line = g.go_before_ternary().trim_space() + ' '
tmp_var = g.new_tmp_var()
g.write('\tstring ${tmp_var} = ')
}
g.write2('str_intp(', node.vals.len.str())
g.write(', _MOV((StrIntpData[]){')
for i, val in node.vals {
Expand Down Expand Up @@ -294,4 +302,15 @@ fn (mut g Gen) string_inter_literal(node ast.StringInterLiteral) {
}
}
g.write('}))')
if g.is_autofree {
g.writeln(';')
g.write(curr_line + tmp_var)
mut scope := g.file.scope.innermost(node.pos.pos)
scope.register(ast.Var{
name: tmp_var
typ: ast.string_type
is_autofree_tmp: true
pos: node.pos
})
}
}
Loading