Fix native library loading in Windows

Motivation:

Windows refuses to load a .DLL file when it's opened by other process.
Recent modification in NativeLibraryLoader causes NativeLibraryLoader to
attempt to load a .DLL before closing its OutputStream. As a result,
loading a .DLL file in Windows always fails.

Modifications:

Close the OutputStream explicitly before loading a shared library.

Result:

Native library loading in Windows works again.
This commit is contained in:
Trustin Lee 2016-08-31 09:01:37 +09:00 committed by Norman Maurer
parent f6c16f4897
commit 4477eb2f48

View File

@ -213,6 +213,11 @@ public final class NativeLibraryLoader {
}
out.flush();
// Close the output stream before loading the unpacked library,
// because otherwise Windows will refuse to load it when it's in use by other process.
closeQuietly(out);
out = null;
loadLibrary(loader, tmpFile.getPath(), true);
} catch (Exception e) {
throw (UnsatisfiedLinkError) new UnsatisfiedLinkError(