Skip to content

Commit

Permalink
Fix reference counting for native contracts (#2732)
Browse files Browse the repository at this point in the history
  • Loading branch information
erikzhang committed May 12, 2022
1 parent 2e31a70 commit 251e4a1
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/neo/SmartContract/Native/NativeContract.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2015-2021 The Neo Project.
// Copyright (C) 2015-2022 The Neo Project.
//
// The neo is free software distributed under the MIT software license,
// see the accompanying file LICENSE in the main directory of the
Expand Down Expand Up @@ -203,13 +203,17 @@ internal async void Invoke(ApplicationEngine engine, byte version)
if (method.NeedApplicationEngine) parameters.Add(engine);
if (method.NeedSnapshot) parameters.Add(engine.Snapshot);
for (int i = 0; i < method.Parameters.Length; i++)
parameters.Add(engine.Convert(context.EvaluationStack.Pop(), method.Parameters[i]));
parameters.Add(engine.Convert(context.EvaluationStack.Peek(i), method.Parameters[i]));
object returnValue = method.Handler.Invoke(this, parameters.ToArray());
if (returnValue is ContractTask task)
{
await task;
returnValue = task.GetResult();
}
for (int i = 0; i < method.Parameters.Length; i++)
{
context.EvaluationStack.Pop();
}
if (method.Handler.ReturnType != typeof(void) && method.Handler.ReturnType != typeof(ContractTask))
{
context.EvaluationStack.Push(engine.Convert(returnValue));
Expand Down

0 comments on commit 251e4a1

Please sign in to comment.