rust-lang / cc-rs

Rust library for build scripts to compile C/C++ code into a Rust library
https://docs.rs/cc
Apache License 2.0
1.82k stars 440 forks source link

Don't try to free DLL on drop #1089

Closed ChrisDenton closed 3 months ago

ChrisDenton commented 3 months ago

Unloading DLLs is an extremely unsafe operation and should not be done without due caution. It's much safer to simply leak it unless we know for certain that it's safe to unload (which is hard to do without co-operations from the DLL itself).

Currently a mitigating factor is that we only use LibraryHandle for kernel32.dll, which is highly unlikely to ever be unloaded, so it's essentially a no-op anyway. However, it would become more of a problem if we ever use LibraryHandle for other DLLs.