Fixed library resource leak on shutdown.