Skip to content

Commit

Permalink
Dispose ApplicationEngine after using (neo-project#1336)
Browse files Browse the repository at this point in the history
  • Loading branch information
erikzhang authored and Tommo-L committed Jun 22, 2020
1 parent 5731275 commit 23db95b
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/neo/Network/RPC/RpcServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public void Dispose()

private JObject GetInvokeResult(byte[] script, IVerifiable checkWitnessHashes = null)
{
ApplicationEngine engine = ApplicationEngine.Run(script, checkWitnessHashes, extraGAS: MaxGasInvoke);
using ApplicationEngine engine = ApplicationEngine.Run(script, checkWitnessHashes, extraGAS: MaxGasInvoke);
JObject json = new JObject();
json["script"] = script.ToHexString();
json["state"] = engine.State;
Expand Down
2 changes: 1 addition & 1 deletion src/neo/Wallets/AssetDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public AssetDescriptor(UInt160 asset_id)
sb.EmitAppCall(asset_id, "name");
script = sb.ToArray();
}
ApplicationEngine engine = ApplicationEngine.Run(script, extraGAS: 3_000_000);
using ApplicationEngine engine = ApplicationEngine.Run(script, extraGAS: 3_000_000);
if (engine.State.HasFlag(VMState.FAULT)) throw new ArgumentException();
this.AssetId = asset_id;
this.AssetName = engine.ResultStack.Pop().GetString();
Expand Down
2 changes: 1 addition & 1 deletion src/neo/Wallets/Wallet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public BigDecimal GetBalance(UInt160 asset_id, params UInt160[] accounts)
sb.EmitAppCall(asset_id, "decimals");
script = sb.ToArray();
}
ApplicationEngine engine = ApplicationEngine.Run(script, extraGAS: 20000000L * accounts.Length);
using ApplicationEngine engine = ApplicationEngine.Run(script, extraGAS: 20000000L * accounts.Length);
if (engine.State.HasFlag(VMState.FAULT))
return new BigDecimal(0, 0);
byte decimals = (byte)engine.ResultStack.Pop().GetBigInteger();
Expand Down

0 comments on commit 23db95b

Please sign in to comment.