Skip to content

Commit

Permalink
Handling null in Transfer method
Browse files Browse the repository at this point in the history
  • Loading branch information
MarekM25 committed Jun 28, 2023
1 parent 823cee7 commit a4d84bf
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/DotNetty.Common/ThreadLocalPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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;
Expand Down

0 comments on commit a4d84bf

Please sign in to comment.