From 23db95b07a10eabe03f691df9beaf2c355a921e6 Mon Sep 17 00:00:00 2001 From: Erik Zhang Date: Fri, 6 Dec 2019 17:01:50 +0800 Subject: [PATCH] Dispose ApplicationEngine after using (#1336) --- src/neo/Network/RPC/RpcServer.cs | 2 +- src/neo/Wallets/AssetDescriptor.cs | 2 +- src/neo/Wallets/Wallet.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/neo/Network/RPC/RpcServer.cs b/src/neo/Network/RPC/RpcServer.cs index 5649cce92f..e2137d517c 100644 --- a/src/neo/Network/RPC/RpcServer.cs +++ b/src/neo/Network/RPC/RpcServer.cs @@ -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; diff --git a/src/neo/Wallets/AssetDescriptor.cs b/src/neo/Wallets/AssetDescriptor.cs index dca0b10b25..46a80a0f5c 100644 --- a/src/neo/Wallets/AssetDescriptor.cs +++ b/src/neo/Wallets/AssetDescriptor.cs @@ -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(); diff --git a/src/neo/Wallets/Wallet.cs b/src/neo/Wallets/Wallet.cs index 52fa839b16..954923df8f 100644 --- a/src/neo/Wallets/Wallet.cs +++ b/src/neo/Wallets/Wallet.cs @@ -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();