memory leak in DiagnosticBuilder.into_diagnostic()
dwrensha opened this issue ยท 6 comments
This code leaks the Box
at self.0
:
rust/src/librustc_errors/diagnostic_builder.rs
Lines 141 to 144 in d3c7934
The leak was introduced in 2fcd870. cc @nnethercote
We could avoid the leak and the unsafe
by doing
let diagnostic = self.0.diagnostic.clone();
self.cancel();
or if we're concerned about performance here, we could maybe do something with drop_in_place()
.
Thanks for the report, I will measure the perf effects of the different alternatives.
I'd like to know how you found this -- code inspection? Some kind of tool?
I found it while running fuzz-rustc and noticing that I kept running out of memory. I turned on -Z sanitizer=address
and this popped out.
Another alternative could be to call std::mem::replace()
to swap in a dummy diagnostic, instead of cloning the existing one.
Below is an example compiler input that triggers the leak:
str// bass (FIXMoo {
}
)
Simpler example that triggers the leak: just a single closing brace
}