Skip to content

Commit 319dc78

Browse files
committed
Fixed unreleased file handles
1 parent d8e84f2 commit 319dc78

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Core.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ public static bool IsCUI(string path) {
172172
var map = CreateFileMapping(file.SafeFileHandle.DangerousGetHandle(), IntPtr.Zero, FILE_PAGE_READONLY, 0, 0, null);
173173
var remap = MapViewOfFile(map, FILE_MAP_READ, 0, 0, 0);
174174
headers = (IMAGE_NT_HEADERS)Marshal.PtrToStructure(ImageNtHeader(remap), typeof(IMAGE_NT_HEADERS));
175+
UnmapViewOfFile(remap);
176+
CloseHandle(remap);
177+
CloseHandle(map);
175178
} catch { }
176179
file.Close();
177180
}
@@ -348,6 +351,11 @@ public static extern IntPtr MapViewOfFile(
348351
uint dwFileOffsetLow,
349352
uint dwNumberOfBytesToMap);
350353

354+
[DllImport("kernel32.dll")]
355+
public static extern bool UnmapViewOfFile(IntPtr lpBaseAddress);
356+
357+
[DllImport("kernel32.dll")]
358+
public static extern void CloseHandle(IntPtr handle);
351359
}
352360
public static class uUser32 {
353361
[DllImport("User32.dll")]

0 commit comments

Comments
 (0)