This code leaks the Box at self.0:
The leak was introduced in 2fcd870711ce267c79408ec631f7eba8e0afcdf6. 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
}
Most helpful comment
Another alternative could be to call
std::mem::replace()to swap in a dummy diagnostic, instead of cloning the existing one.