Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Hecate2 committed Oct 9, 2024
1 parent 8290697 commit 792205a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Neo.VM/ExecutionEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ public T Pop<T>() where T : StackItem
/// </summary>
protected virtual void PostExecuteInstruction(Instruction instruction)
{
if (ReferenceCounter.Count < Limits.MaxStackSize) return;
if (ReferenceCounter.Count <= Limits.MaxStackSize) return;
if (ReferenceCounter.CheckZeroReferred() > Limits.MaxStackSize)
throw new InvalidOperationException($"MaxStackSize exceed: {ReferenceCounter.Count}");
}
Expand Down
1 change: 1 addition & 0 deletions src/Neo.VM/JumpTable/JumpTable.Compound.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public virtual void Unpack(ExecutionEngine engine, Instruction instruction)
default:
throw new InvalidOperationException($"Invalid type for {instruction.OpCode}: {compound.Type}");
}
engine.ReferenceCounter.TryCleanTrackedItem(compound);
engine.Push(compound.Count);
}

Expand Down
11 changes: 11 additions & 0 deletions src/Neo.VM/ReferenceCounter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -292,5 +292,16 @@ internal void RemoveStackReference(StackItem item)
if (--item.StackReferences == 0)
_zeroReferred.Add(item);
}

internal bool TryCleanTrackedItem(StackItem item)
{
if (item.StackReferences > 0 || item.ObjectReferences?.Values.Any(p => p.References > 0 && p.Item.OnStack) == true)
// Still referred by stack or some compound item
return false;
if (item is CompoundType compound)
_referencesCount -= compound.SubItemsCount;
item.Cleanup();
return _trackedItems.Remove(item);
}
}
}

0 comments on commit 792205a

Please sign in to comment.