Skip to content

Commit

Permalink
RegistryManager: StreamWriter is now disposed on lock release.
Browse files Browse the repository at this point in the history
Part of KSP-CKAN#1357.
  • Loading branch information
pjf authored and politas committed Aug 17, 2016
1 parent c15eb91 commit 01f1ccb
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions Core/Registry/RegistryManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class RegistryManager : IDisposable
private readonly string path;
public readonly string lockfile_path;
private FileStream lockfile_stream = null;
private StreamWriter lockfile_writer = null;

private readonly TxFileManager file_transaction = new TxFileManager();

Expand Down Expand Up @@ -110,9 +111,9 @@ public bool GetLock()
lockfile_stream = new FileStream(lockfile_path, FileMode.CreateNew, FileAccess.Write, FileShare.None, 512, FileOptions.DeleteOnClose);

// Write the current process ID to the file.
StreamWriter writer = new StreamWriter(lockfile_stream);
writer.Write(Process.GetCurrentProcess().Id);
writer.Flush();
lockfile_writer = new StreamWriter(lockfile_stream);
lockfile_writer.Write(Process.GetCurrentProcess().Id);
lockfile_writer.Flush();
}
catch (IOException)
{
Expand All @@ -132,6 +133,13 @@ public void ReleaseLock()
lockfile_stream.Close();
lockfile_stream = null;
}

// This may not be needed when the underlying stream is closed,
// but doesn't hurt.
if (lockfile_writer != null)
{
lockfile_writer.Dispose();
}
}

/// <summary>
Expand Down

0 comments on commit 01f1ccb

Please sign in to comment.