v icon indicating copy to clipboard operation
v copied to clipboard

Flag parsing error with -autofree

Open amoyyy opened this issue 4 years ago • 1 comments
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.

amoyyy avatar Sep 17 '21 08:09 amoyyy

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

Le0Developer avatar Nov 28 '21 14:11 Le0Developer

Works in latest V (V 0.4.12 9772649).

dy-tea avatar Sep 30 '25 08:09 dy-tea