Skip to content

Commit

Permalink
Fix ReadBufferState dispose cases (#110739)
Browse files Browse the repository at this point in the history
* Move ReadBufferState initialization after other operations

* Move ReadBufferState initialization after other operations

* Update src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/JsonTypeInfoOfT.ReadHelper.cs

* Move ReadBufferState initialization under try clause

* Move ReadBufferState initialization under try clause

* Return initial change. Add explanatory comment

* Return initial change. Add explanatory comment

* Fix typo

* Fix typo

* Update comment

* Update comment

* Change bufferState initialization style

---------

Co-authored-by: Eirik Tsarpalis <[email protected]>
  • Loading branch information
MaxPatri and eiriktsarpalis authored Dec 22, 2024
1 parent 57ab984 commit 004f205
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -553,10 +553,11 @@ public static partial class JsonSerializer
{
Debug.Assert(listTypeInfo.IsConfigured);

ReadBufferState bufferState = new(listTypeInfo.Options.DefaultBufferSize);
ReadStack readStack = default;
readStack.Initialize(listTypeInfo, supportContinuation: true);
JsonReaderState jsonReaderState = new(readerOptions);
// Note: The ReadBufferState ctor rents pooled buffers.
ReadBufferState bufferState = new(listTypeInfo.Options.DefaultBufferSize);

try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ public partial class JsonTypeInfo<T>
{
Debug.Assert(IsConfigured);
JsonSerializerOptions options = Options;
var bufferState = new ReadBufferState(options.DefaultBufferSize);
ReadStack readStack = default;
readStack.Initialize(this, supportContinuation: true);
var jsonReaderState = new JsonReaderState(options.GetReaderOptions());
// Note: The ReadBufferState ctor rents pooled buffers.
ReadBufferState bufferState = new(options.DefaultBufferSize);

try
{
Expand Down Expand Up @@ -58,10 +59,11 @@ public partial class JsonTypeInfo<T>
{
Debug.Assert(IsConfigured);
JsonSerializerOptions options = Options;
var bufferState = new ReadBufferState(options.DefaultBufferSize);
ReadStack readStack = default;
readStack.Initialize(this, supportContinuation: true);
var jsonReaderState = new JsonReaderState(options.GetReaderOptions());
// Note: The ReadBufferState ctor rents pooled buffers.
ReadBufferState bufferState = new(options.DefaultBufferSize);

try
{
Expand Down

0 comments on commit 004f205

Please sign in to comment.