Skip to content

Commit 016e4ab

Browse files
authored
Merge pull request #19 from ReneLergner/master
Fixes for 2 memory-leaks
2 parents 9392872 + 1ce8e3b commit 016e4ab

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,8 @@
33
**/obj
44
packages/
55
/*.suo
6+
/.vs/Capstone.NET/v15/Server/sqlite3/db.lock
7+
/.vs/Capstone.NET/v15/Server/sqlite3/storage.ide
8+
/.vs/Capstone.NET/v15/Server/sqlite3/storage.ide-shm
9+
/.vs/Capstone.NET/v15/Server/sqlite3/storage.ide-wal
10+
/.vs/Capstone.NET/v15/.suo

Gee.External.Capstone/CapstoneDisassembler.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -225,13 +225,15 @@ protected CapstoneDisassembler(DisassembleArchitecture architecture, Disassemble
225225
/// Thrown if the binary code could not be disassembled.
226226
/// </exception>
227227
public Instruction<TArchitectureInstruction, TArchitectureRegister, TArchitectureGroup, TArchitectureDetail>[] Disassemble(byte[] code, int count, long startingAddress) {
228-
var nativeInstructions = NativeCapstone.Disassemble(this.Handle, code, count, startingAddress);
229-
var instructions = nativeInstructions
230-
.Instructions
231-
.Select(this.CreateInstruction)
232-
.ToArray();
233-
234-
return instructions;
228+
using (var nativeInstructions = NativeCapstone.Disassemble(this.Handle, code, count, startingAddress))
229+
{
230+
var instructions = nativeInstructions
231+
.Instructions
232+
.Select(this.CreateInstruction)
233+
.ToArray();
234+
235+
return instructions;
236+
}
235237
}
236238

237239
/// <summary>
@@ -547,6 +549,9 @@ public bool MoveNext() {
547549

548550
var iResultCode = (int) pResultCode;
549551
var nativeInstructions = MarshalExtension.PtrToStructure<NativeInstruction>(pInstructions, iResultCode);
552+
553+
Marshal.FreeHGlobal(pInstructions);
554+
550555
if (nativeInstructions == null || nativeInstructions.Length == 0) {
551556
return false;
552557
}

0 commit comments

Comments
 (0)