Skip to content

verilog: failed attempt to fix leak #5189

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

Closed

Conversation

widlarizer
Copy link
Collaborator

Non-functional half-attempt at addressing #5180 (comment)

@garytwong
Copy link
Contributor

garytwong commented Jun 20, 2025

Thank you for the debugging, and apologies for introducing the error! I can reproduce the issue and am contemplating a fix.

My inclination is that it might be cleaner to omit the delete from the TOK_IF handling around verilog_parser.y:2885, and instead defer cleanup until the end during optional_else handling at line 2906. It would require a bit more processing there to detect the case where an else if branch inside a unique if has orphaned the AST_BLOCK node created earlier. That's when the outstanding reference I had missed will be dropped by ast_stack.pop_back, and so ought to be the proper time to deallocate. But I don't have an implementation yet.

I expect to have more time to investigate in ~12 hours, unless you want to fix it first.

Thanks again!

@garytwong
Copy link
Contributor

Please disregard my suggestion above... while that approach could probably have been made to work, it got complicated quickly. Your idea to clean up ast_stack directly is definitely better.

I rearranged your fix a little bit and now have a patch to run tests/verilog/unique_if_enc.ys and @KrystalDelusion's minimal test case from #5152 under SANITIZER=address with no use-after-free and no leaks. (See commit 50ac69d.) I will play with it a bit more to test there are no other regressions.

@garytwong
Copy link
Contributor

OK, I've tested commit 50ac69d further and it seems to pass testing with SANITIZER=address for me. Should I submit a new PR on that revision? Or should I let you finish this one? Or something else?

@KrystalDelusion
Copy link
Member

Should I submit a new PR on that revision?

That would be great, thanks :)

@widlarizer widlarizer added the status-superseded Status: Work continues in a different PR or was made redundant label Jun 23, 2025
@widlarizer
Copy link
Collaborator Author

superseded by #5193

@widlarizer widlarizer closed this Jun 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status-superseded Status: Work continues in a different PR or was made redundant
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants