Fix ILVerifier holding files open (#89127)
authorMike Voorhees <mrvoorhe@users.noreply.github.com>
Wed, 19 Jul 2023 10:41:22 +0000 (06:41 -0400)
committerGitHub <noreply@github.com>
Wed, 19 Jul 2023 10:41:22 +0000 (03:41 -0700)
commit14036c51a1b31a37ec87ce017c32f6ab430e7f2a
tree3958a41527688feebd57813b3bdba323664dd9cd
parentdeca993d48b887dd958a37372930269dbc60f977
Fix ILVerifier holding files open (#89127)

There were a couple things to fix

1) `PEReader` implements `IDisposable` and needs to be disposed.  Not least because it is managing the lifetime of the streams opened by `File.OpenRead` calls inside `ILVerifier`

2) In order to dispose of of the pereaders, add `IDisposable` to `ILVerifier` and add a `using` to the caller that creates a new instance.

(1) and (2) fix the issues with files being held open.

While looking at the code, I didn't see a reason why `TryLoadAssemblyFromFolder` couldn't check the `_assemblyCache` before creating a opening a new stream and creating a new pereader.  I don't think this was causing any issues.  It just seemed like a harmless just-in-case change.
src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/ILVerifier.cs
src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs