Skip to content

Commit 0e7959c

Browse files
committed
fix: Critical premature free bug
1 parent 165576a commit 0e7959c

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

MemoryModule/NativeAssembly.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,17 +172,16 @@ protected static bool FreeLibraryHandle(IntPtr handle)
172172
{
173173
try
174174
{
175-
if (handle != IntPtr.Zero)
175+
if (handle != IntPtr.Zero && _handles.ContainsKey(handle))
176176
{
177177
var info = _handles[handle];
178-
179-
NativeAssemblyImpl.FreeLibrary(handle);
180-
_handles.Remove(handle);
181-
182178
--info.RefCount;
183179

184180
if (info.RefCount == 0)
185181
{
182+
NativeAssemblyImpl.FreeLibrary(handle);
183+
_handles.Remove(handle);
184+
186185
var nameSet = _libraryMap[info.Name];
187186
nameSet.Remove(handle);
188187

0 commit comments

Comments
 (0)