Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

make sure that SymbolReader.Dispose closes all opened pdb files #979

Merged
merged 4 commits into from
Oct 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/TraceEvent/Symbols/PortableSymbolModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@

namespace Microsoft.Diagnostics.Symbols
{
internal class PortableSymbolModule : ManagedSymbolModule
internal class PortableSymbolModule : ManagedSymbolModule, IDisposable
{
public PortableSymbolModule(SymbolReader reader, string pdbFileName) : this(reader, File.Open(pdbFileName, FileMode.Open, FileAccess.Read, FileShare.Read), pdbFileName) { }

public PortableSymbolModule(SymbolReader reader, Stream stream, string pdbFileName = "") : base(reader, pdbFileName)
{
_stream = stream;
_provider = MetadataReaderProvider.FromPortablePdbStream(_stream);
_provider = MetadataReaderProvider.FromPortablePdbStream(stream);
_metaData = _provider.GetMetadataReader();
}

public void Dispose() => _provider.Dispose();

public override Guid PdbGuid
{
get
Expand Down Expand Up @@ -125,7 +126,6 @@ internal PortablePdbSourceFile(Document sourceFileDocument, PortableSymbolModule
// Needed by other things to look up data
internal MetadataReader _metaData;
private MetadataReaderProvider _provider;
private Stream _stream;
#endregion
}
}
Expand Down
10 changes: 7 additions & 3 deletions src/TraceEvent/Symbols/SymbolReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ public ManagedSymbolModule OpenSymbolFile(string pdbFilePath)
if (firstBytes[0] == 'B' && firstBytes[1] == 'S' && firstBytes[2] == 'J' && firstBytes[3] == 'B')
{
stream.Seek(0, SeekOrigin.Begin); // Start over
ret = new PortableSymbolModule(this, pdbFilePath);
ret = new PortableSymbolModule(this, stream, pdbFilePath);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a minor bug fix: this method opens a stream, seeks to the begining of it but when it creates and instance of PortableSymbolModule it does not reuse the stream but instead calls a ctor that opens the file one more time:

public PortableSymbolModule(SymbolReader reader, string pdbFileName) : this(reader, File.Open(pdbFileName, FileMode.Open, FileAccess.Read, FileShare.Read), pdbFileName) { }

so far we always had the file opened twice

}
else
{
Expand Down Expand Up @@ -912,9 +912,13 @@ private void InsurePathIsInNIC(TextWriter log, ref string ngenImageFullPath)
}

/// <summary>
/// Called when you are done with the symbol reader. Currently does nothing.
/// Called when you are done with the symbol reader.
/// Closes all opened symbol files.
/// </summary>
public void Dispose() { }
public void Dispose()
{
m_symbolModuleCache.Clear();
}

#region private
/// <summary>
Expand Down
4 changes: 4 additions & 0 deletions src/TraceEvent/Utilities/Cache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ public void Clear()
for (int i = 0; i < m_entries.Length; i++)
{
m_entries[i].Key = default(K);
if (m_entries[i].Value != null && m_entries[i].Value is IDisposable disposable)
{
disposable.Dispose();
}
m_entries[i].Value = null;
}
// indicate the free entries.
Expand Down