If api_init raises before assigning to the library member, api_free will attempt to FreeLibrary an uninitialized value.
This will result in undefined behavior (an access violation, more often than not).
With a debugger attached to ruby.exe, it's easy to reproduce with: Win32::API.new('foo', 'V', 'V', 'foo'), without a foo.dll on the load path, and waiting for the API object to be collected.
If api_init raises before assigning to the library member, api_free will attempt to FreeLibrary an uninitialized value. This will result in undefined behavior (an access violation, more often than not). With a debugger attached to ruby.exe, it's easy to reproduce with:
Win32::API.new('foo', 'V', 'V', 'foo')
, without a foo.dll on the load path, and waiting for the API object to be collected.