fix the possible crash on unload, explanation in source comment