Memory leak from BaseType::unify
Open
Nobody has claimed this yet.
bug
cleanup
- Dominant language
- C++
- Stars
- 2.9k
- Forks
- 230
- Avg merge
- 19h 55m
- Merged PRs (30d)
- 67
Description
BaseType::unify returns a pointer to a newly-created Ty on the heap. The caller should be responsible for releasing the memory. As it is, many, many callers are not doing that.
Example of a memory leak(rust-hir-type-check-item.h:58)
auto result = TypeCheckExpr::Resolve (function.function_body.get (), false);
auto ret_resolved = expected_ret_tyty->unify (result); // Memory is allocated here
if (ret_resolved == nullptr)
return;
context->peek_return_type ()->append_reference (ret_resolved->get_ref ());
context->pop_return_type ();
} // Pointer goes out of scope here
(Alas, we never worry about such issues in Rust)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at BaseType::unify and inspect the example caller at rust-hir-type-check-item.h:58. Trace how the newly allocated Ty is returned and how callers handle it, then identify the other callers that fail to release it. Done means the affected callers no longer leak the memory while preserving the existing unify behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100