v
v copied to clipboard
Flag parsing error with -autofree
trafficstars
V version: V 0.2.4 92bb292 OS: ubuntu 20.04.3LTS
What did you do? main.v:
module main
import os
import flag
fn main() {
mut fp := flag.new_flag_parser(os.args)
fp.application('test')
fp.version('v0.0.1')
fp.description('东海流波,风雨闻声')
fp.skip_executable()
input_path := fp.string('input', `i`, 'input', 'path of inputfile')
additional_args := fp.finalize() or {
eprintln(err)
println(fp.usage())
return
}
println('a_string: "$input_path" ')
println(additional_args.join_lines())
}
v -autofree main.v && ./main -i helloworld
What did you expect to see?
a_string: "helloworld"
What did you see instead?
a_string: "no such fl"
Compiled without -autofreeflag, things went ok. It seems that the flag parser has a memory error.
import os
import flag
fn main() {
mut fp := flag.new_flag_parser(os.args)
println(fp.usage()) // not needed for the runtime error
}
Causes the following runtime error with -autofree on macos:
repro(42504,0x11b978dc0) malloc: *** error for object 0x7f86b0c061c0: pointer being freed was not allocated
repro(42504,0x11b978dc0) malloc: *** set a breakpoint in malloc_error_break to debug
Works in latest V (V 0.4.12 9772649).