Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fix ReadBufferState dispose cases #110739

Merged
merged 14 commits into from
Dec 22, 2024
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ public partial class JsonTypeInfo<T>
ReadStack readStack = default;
readStack.Initialize(this, supportContinuation: true);
var jsonReaderState = new JsonReaderState(options.GetReaderOptions());
ReadBufferState bufferState = null;
// bufferState is initialized last to exlcude any exceptions before entering the try/finally block where bufferState.Dispose call is executed
var bufferState = new ReadBufferState(options.DefaultBufferSize);

try
eiriktsarpalis marked this conversation as resolved.
Show resolved Hide resolved
{
bufferState = new ReadBufferState(options.DefaultBufferSize);
while (true)
{
bufferState = await bufferState.ReadFromStreamAsync(utf8Json, cancellationToken).ConfigureAwait(false);
Expand Down Expand Up @@ -62,11 +62,11 @@ public partial class JsonTypeInfo<T>
ReadStack readStack = default;
readStack.Initialize(this, supportContinuation: true);
var jsonReaderState = new JsonReaderState(options.GetReaderOptions());
ReadBufferState bufferState = null;
// bufferState is initialized last to exlcude any exceptions before entering the try/finally block where bufferState.Dispose call is executed
var bufferState = new ReadBufferState(options.DefaultBufferSize);

try
eiriktsarpalis marked this conversation as resolved.
Show resolved Hide resolved
{
bufferState = new ReadBufferState(options.DefaultBufferSize);
while (true)
{
bufferState.ReadFromStream(utf8Json);
Expand Down
Loading