if (param_free) { SECITEM_FreeItem(param_free,PR_TRUE); }
PK11_WrapPrivKey(PK11SlotInfo *slot, PK11SymKey *wrappingKey, 		 SECKEYPrivateKey *privKey, CK_MECHANISM_TYPE wrapType, 		 SECItem *param, SECItem *wrappedKey, void *wincx){    PK11SlotInfo     *privSlot   = privKey->pkcs11Slot; /* The slot where							 * the private key							 * we are going to							 * wrap lives.							 */    PK11SymKey       *newSymKey  = NULL;    SECKEYPrivateKey *newPrivKey = NULL;    SECItem          *param_free = NULL;    CK_ULONG          len        = wrappedKey->len;    CK_MECHANISM      mech;    CK_RV             crv;    if (!privSlot || !PK11_DoesMechanism(privSlot, wrapType)) {        /* Figure out a slot that does the mechanism and try to import	 * the private key onto that slot.	 */        PK11SlotInfo *int_slot = PK11_GetInternalSlot();	privSlot = int_slot; /* The private key has a new home */	newPrivKey = pk11_loadPrivKey(privSlot,privKey,NULL,PR_FALSE,PR_FALSE);	/* newPrivKey has allocated its own reference to the slot, so it's	 * safe until we destroy newPrivkey.	 */	PK11_FreeSlot(int_slot);	if (newPrivKey == NULL) {	    return SECFailure;	}	privKey = newPrivKey;    }    if (privSlot != wrappingKey->slot) {        newSymKey = pk11_CopyToSlot (privSlot, wrapType, CKA_WRAP, 				     wrappingKey);	wrappingKey = newSymKey;    }    if (wrappingKey == NULL) {        if (newPrivKey) {		SECKEY_DestroyPrivateKey(newPrivKey);	}	return SECFailure;    }    mech.mechanism = wrapType;    if (!param) {        param = param_free = PK11_ParamFromIV(wrapType, NULL);    }    if (param) {        mech.pParameter     = param->data;	mech.ulParameterLen = param->len;    } else {        mech.pParameter     = NULL;	mech.ulParameterLen = 0;    }    PK11_EnterSlotMonitor(privSlot);    crv = PK11_GETTAB(privSlot)->C_WrapKey(privSlot->session, &mech, 					   wrappingKey->objectID, 					   privKey->pkcs11ID,					   wrappedKey->data, &len);    PK11_ExitSlotMonitor(privSlot);    if (newSymKey) {        PK11_FreeSymKey(newSymKey);    }    if (newPrivKey) {        SECKEY_DestroyPrivateKey(newPrivKey);    }    if (crv != CKR_OK) {        PORT_SetError( PK11_MapError(crv) );	return SECFailure;    }    wrappedKey->len = len;    return SECSuccess;}