Skip to content

checker: fix autofree crash with option/result method chains#26694

Merged
JalonSolov merged 2 commits into
vlang:masterfrom
tankf33der:autofree_chain
Mar 7, 2026
Merged

checker: fix autofree crash with option/result method chains#26694
JalonSolov merged 2 commits into
vlang:masterfrom
tankf33der:autofree_chain

Conversation

@tankf33der

Copy link
Copy Markdown
Contributor

This is preliminary preparation for fixing examples/toml.v in -autofree mode.
Finally found a situation in which Claude Code is a bad assistant — making a test based on a diff — they all work on the master branch :), it hallucinates and goes in circles.

In this case, it was possible to create tests in semi-manual mode and make a minimal meaningful fix. In the future, I will try to always create test files for -autofree mode.

All vlib/ tests passed.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9a90e1143d

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread vlib/v/checker/fn.v
}
if arg.expr in [ast.Ident, ast.StringLiteral, ast.SelectorExpr, ast.ComptimeSelector]
|| (arg.expr is ast.CallExpr && arg.expr.or_block.kind != .absent) {
|| autofree_expr_has_or_block_in_chain(arg.expr) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Keep freeing chained option/result string arguments

When -autofree is enabled, this new guard skips setting is_tmp_autofree for string args like process(get_str()!.to_upper()), so cgen no longer materializes/freees the temp argument for that expression. In vlib/v/gen/c/fn.v the post-call cleanup path is gated on arg.is_tmp_autofree (use_tmp_var_autofree and temp-var emission), so these chained option/result method calls now leak the allocated string result instead of being freed after the call; this affects any hot path using option/result propagation in string argument chains.

Useful? React with 👍 / 👎.

@tankf33der

Copy link
Copy Markdown
Contributor Author

And now after codex review Sanitized CI failed with memory leak detected.
I am on it.

@tankf33der

Copy link
Copy Markdown
Contributor Author

Lesson learned. The strategic purpose of this venture was simply to learn how to compile examples/*.v files; fighting memory leaks on top of that is too much, especially since all -autofree tests have ASAN checks disabled.

Yes, there is leak in test, I was able to reproduce them manually on my own stand, so in the future it will be easier to deal with them, but for now just disable.

@JalonSolov JalonSolov merged commit 3324dd3 into vlang:master Mar 7, 2026
90 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.

2 participants