From a4d84bf2787a3441a7adab66f3a266b533e08841 Mon Sep 17 00:00:00 2001 From: MarekM25 Date: Wed, 28 Jun 2023 15:19:46 +0200 Subject: [PATCH] Handling null in Transfer method --- src/DotNetty.Common/ThreadLocalPool.cs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/DotNetty.Common/ThreadLocalPool.cs b/src/DotNetty.Common/ThreadLocalPool.cs index 327cb15e..c4819bc5 100644 --- a/src/DotNetty.Common/ThreadLocalPool.cs +++ b/src/DotNetty.Common/ThreadLocalPool.cs @@ -236,7 +236,7 @@ internal void Add(DefaultHandle handle) // transfer as many items as we can from this queue to the stack, returning true if any were transferred internal bool Transfer(Stack dst) { - Link head = this.head.link; + Link head = this.head?.link; if (head == null) { return false; @@ -259,6 +259,11 @@ internal bool Transfer(Stack dst) return false; } + if (dst?.elements == null) + { + return false; + } + int dstSize = dst.size; int expectedCapacity = dstSize + srcSize; @@ -273,9 +278,19 @@ internal bool Transfer(Stack dst) DefaultHandle[] srcElems = head.elements; DefaultHandle[] dstElems = dst.elements; int newDstSize = dstSize; + if (head.elements == null) + { + return false; + } + for (int i = srcStart; i < srcEnd; i++) { DefaultHandle element = srcElems[i]; + if (element == null) + { + return false; + } + if (element.recycleId == 0) { element.recycleId = element.lastRecycledId;