Skip to content

Commit

Permalink
Move NativeLibrary.Free null check to managed (dotnet/coreclr#27744)
Browse files Browse the repository at this point in the history
Commit migrated from dotnet/coreclr@4ef94ad
  • Loading branch information
CoffeeFlux authored and AaronRobinsonMSFT committed Nov 8, 2019
1 parent 7e4d9f8 commit 1a44577
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
6 changes: 1 addition & 5 deletions src/coreclr/src/vm/dllimport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6519,11 +6519,7 @@ NATIVE_LIBRARY_HANDLE NDirect::LoadLibraryModuleBySearch(NDirectMethodDesc * pMD
void NDirect::FreeNativeLibrary(NATIVE_LIBRARY_HANDLE handle)
{
STANDARD_VM_CONTRACT;

// FreeLibrary doesn't throw if the input is null.
// This avoids further null propagation/check while freeing resources (ex: in finally blocks)
if (handle == NULL)
return;
_ASSERTE(handle != NULL);

#ifndef FEATURE_PAL
BOOL retVal = FreeLibrary(handle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ public static bool TryLoad(string libraryName, Assembly assembly, DllImportSearc
/// <param name="handle">The native library handle to be freed</param>
public static void Free(IntPtr handle)
{
if (handle == IntPtr.Zero)
return;
FreeLib(handle);
}

Expand Down

0 comments on commit 1a44577

Please sign in to comment.