When reusing a PKCS11_SLOT_PRIVATE structure instance, the instance to be reused was accidentally freed
Looking for an instance in the list of slots had bugs in pointer usage (treating slotp as an array of PKCS11_SLOT*, while it is actually a pointer to an array of PKCS11_SLOT).
On refreshing slots, there were two issues: