From 6a47672056b3dc985d20d31643c7eb90a181b6ef Mon Sep 17 00:00:00 2001 From: Ziya Suzen Date: Thu, 21 Nov 2024 06:57:22 +0000 Subject: [PATCH] Fix memory leak by disposing JsonDocument properly --- src/NATS.Client.JetStream/NatsJSContext.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NATS.Client.JetStream/NatsJSContext.cs b/src/NATS.Client.JetStream/NatsJSContext.cs index 359c86bb9..8876a200c 100644 --- a/src/NATS.Client.JetStream/NatsJSContext.cs +++ b/src/NATS.Client.JetStream/NatsJSContext.cs @@ -335,7 +335,7 @@ internal async ValueTask>> TryJSRequestAsyn // .NET 6 new APIs to the rescue: we can read the buffer once // by deserializing into a document, inspect and using the new // API deserialize to the final type from the document. - var jsonDocument = msg.Data; + using var jsonDocument = msg.Data; if (jsonDocument.RootElement.TryGetProperty("error", out var errorElement)) {