Skip to content

Commit

Permalink
Don't stack overflow when disposing ReusableStringWriter (#1977)
Browse files Browse the repository at this point in the history
* Don't stack overflow when disposing ReusableStringWriter

* Don't attempt to reuse a pooled writer if it's being finalized
  • Loading branch information
nblumhardt committed Nov 10, 2023
1 parent ca4efda commit 16739f0
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Serilog/Rendering/ReusableStringWriter.cs
Expand Up @@ -39,10 +39,16 @@ public static StringWriter GetOrCreate(IFormatProvider? formatProvider = null)
/// </summary>
protected override void Dispose(bool disposing)
{
if (!disposing)
{
base.Dispose(disposing);
return;
}

var sb = GetStringBuilder();
if (sb.Capacity > StringBuilderCapacityThreshold)
{
base.Dispose();
base.Dispose(disposing);
return;
}
// We don't call base.Dispose because all it does is mark the writer as closed so it can't be
Expand Down

0 comments on commit 16739f0

Please sign in to comment.