Skip to content

autofree,flag: fix double free in FlagParser free#25336

Merged
spytheman merged 1 commit into
vlang:masterfrom
dy-tea:master
Sep 18, 2025
Merged

autofree,flag: fix double free in FlagParser free#25336
spytheman merged 1 commit into
vlang:masterfrom
dy-tea:master

Conversation

@dy-tea

@dy-tea dy-tea commented Sep 17, 2025

Copy link
Copy Markdown
Member

Fixes #9815.

It seems to me like calling these frees on f.args frees os.args only on -autofree? Not sure why that would happen since os.args is always cloned.

I set it to @[manualfree] here but it might actually end up leaking some memory since the new_flag_parser function creates some clones, but it was preferable to freeing the variables before (and after) returning them?

A few flag tests still fail with autofree but not in a way related to this issue.

@vlang vlang deleted a comment from huly-for-github Bot Sep 18, 2025

@spytheman spytheman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work, however I think that the problem, may be in the args.clone() call, for []string , which does not clone the individual elements/strings of the array.

@spytheman spytheman merged commit 23602c1 into vlang:master Sep 18, 2025
72 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compiling string flag with -autofree ends in heap-corruption

2 participants