codespecs / daikon

Dynamic detection of likely invariants
http://plse.cs.washington.edu/daikon/
Other
214 stars 54 forks source link

Fix a possible resource leak in the `Session` constructor #524

Closed Calvin-L closed 11 months ago

Calvin-L commented 11 months ago

(Discovered by https://github.com/typetools/checker-framework/pull/6241)

After opening the output stream trace_file, the constructor goes on to do many initialization tasks that might throw exceptions. If that happens, the constructor exits with a SimplifyError and does not close trace_file, leaking the open output stream. There is no way for a caller to clean it up because the partially-constructed Session is not accessible after the constructor throws.

This commit fixes the problem using a temporary variable with the same name. On exception the temporary variable will be closed before the constructor exits.

This commit also makes an effort to preserve the entire exception chain on failure, which can be helpful for debugging because it preserves the entire stack trace.

mernst commented 11 months ago

Thanks for this fix!