if (slot->objectLock == NULL) return CKR_HOST_MEMORY;
if (slot->objectLock == NULL) goto mem_loser;
PK11_SlotInit(char *configdir,pk11_token_parameters *params, int moduleIndex){    unsigned int i;    CK_SLOT_ID slotID = params->slotID;    PK11Slot *slot = pk11_NewSlotFromID(slotID, moduleIndex);    PRBool needLogin = !params->noKeyDB;    CK_RV crv;    if (slot == NULL) {	return CKR_HOST_MEMORY;    }    slot->optimizeSpace = params->optimizeSpace;    if (slot->optimizeSpace) {	slot->tokObjHashSize = SPACE_TOKEN_OBJECT_HASH_SIZE;	slot->sessHashSize = SPACE_SESSION_HASH_SIZE;	slot->numSessionLocks = 1;    } else {	slot->tokObjHashSize = TIME_TOKEN_OBJECT_HASH_SIZE;	slot->sessHashSize = TIME_SESSION_HASH_SIZE;	slot->numSessionLocks = slot->sessHashSize/BUCKETS_PER_SESSION_LOCK;    }    slot->sessionLockMask = slot->numSessionLocks-1;#ifdef PKCS11_USE_THREADS    slot->slotLock = PZ_NewLock(nssILockSession);    if (slot->slotLock == NULL) {	return CKR_HOST_MEMORY;    }    slot->sessionLock = (PZLock **)			PORT_ZAlloc(slot->numSessionLocks * sizeof(PZLock *));    if (slot->sessionLock == NULL) {	return CKR_HOST_MEMORY;    }    for (i=0; i < slot->numSessionLocks; i++) {        slot->sessionLock[i] = PZ_NewLock(nssILockSession);        if (slot->sessionLock[i] == NULL) return CKR_HOST_MEMORY;    }    slot->objectLock = PZ_NewLock(nssILockObject);    if (slot->objectLock == NULL) return CKR_HOST_MEMORY;#else    slot->slotLock = NULL;    slot->sessionLock = (PZLock **)			PORT_ZAlloc(slot->numSessionLocks * sizeof(PZLock *));    if (slot->sessionLock == NULL) {	return CKR_HOST_MEMORY;    }    for (i=0; i < slot->numSessionLocks; i++) {        slot->sessionLock[i] = NULL;    }    slot->objectLock = NULL;#endif    slot->head = (PK11Session **)		PORT_ZAlloc(slot->sessHashSize*sizeof(PK11Session *));    if (slot->head == NULL) {	return CKR_HOST_MEMORY;    }    slot->tokObjects = (PK11Object **)		PORT_ZAlloc(slot->tokObjHashSize*sizeof(PK11Object *));    if (slot->tokObjects == NULL) {	return CKR_HOST_MEMORY;    }    slot->tokenHashTable = PL_NewHashTable(64,pk11_HashNumber,PL_CompareValues,					SECITEM_HashCompare, NULL, 0);    if (slot->tokenHashTable == NULL) {	return CKR_HOST_MEMORY;    }    slot->password = NULL;    slot->hasTokens = PR_FALSE;    slot->sessionIDCount = 0;    slot->sessionIDConflict = 0;    slot->sessionCount = 0;    slot->rwSessionCount = 0;    slot->tokenIDCount = 1;    slot->needLogin = PR_FALSE;    slot->isLoggedIn = PR_FALSE;    slot->ssoLoggedIn = PR_FALSE;    slot->DB_loaded = PR_FALSE;    slot->slotID = slotID;    slot->certDB = NULL;    slot->keyDB = NULL;    slot->minimumPinLen = 0;    slot->readOnly = params->readOnly;    pk11_setStringName(params->tokdes ? params->tokdes : 	pk11_getDefTokName(slotID), slot->tokDescription, 						sizeof(slot->tokDescription));    pk11_setStringName(params->slotdes ? params->slotdes : 	pk11_getDefSlotName(slotID), slot->slotDescription, 						sizeof(slot->slotDescription));    if ((!params->noCertDB) || (!params->noKeyDB)) {	crv = pk11_DBInit(params->configdir ? params->configdir : configdir,		params->certPrefix, params->keyPrefix, params->readOnly,		params->noCertDB, params->noKeyDB, params->forceOpen, 						&slot->certDB, &slot->keyDB);	if (crv != CKR_OK) {	    /* shoutdown slot? */	    return crv;	}	if (nsslowcert_needDBVerify(slot->certDB)) {	    pk11_DBVerify(slot);	}    }    if (needLogin) {	/* if the data base is initialized with a null password,remember that */	slot->needLogin = 		(PRBool)!pk11_hasNullPassword(slot->keyDB,&slot->password);	if (params->minPW <= PK11_MAX_PIN) {	    slot->minimumPinLen = params->minPW;	}	if ((slot->minimumPinLen == 0) && (params->pwRequired) && 		(slot->minimumPinLen <= PK11_MAX_PIN)) {	    slot->minimumPinLen = 1;	}    }    return CKR_OK;}