tokenNameList[i] = NS_ConvertUTF8toUCS2(PK11_GetTokenName(slotElement->slot)).ToNewUnicode();
tokenNameList[i] = ToNewUnicode(NS_ConvertUTF8toUCS2(PK11_GetTokenName(slotElement->slot)));
GetSlotWithMechanism(PRUint32 aMechanism,                      nsIInterfaceRequestor *m_ctx,                     PK11SlotInfo** aSlot){    PK11SlotList * slotList = nsnull;    PRUnichar** tokenNameList = nsnull;    nsITokenDialogs * dialogs;    PRUnichar *unicodeTokenChosen;    PK11SlotListElement *slotElement, *tmpSlot;    PRUint32 numSlots = 0, i = 0;    PRBool canceled;    nsresult rv = NS_OK;    *aSlot = nsnull;    // Get the slot    slotList = PK11_GetAllTokens(MapGenMechToAlgoMech(aMechanism),                                 PR_TRUE, PR_TRUE, m_ctx);    if (!slotList || !slotList->head) {        rv = NS_ERROR_FAILURE;        goto loser;    }    if (!slotList->head->next) {        /* only one slot available, just return it */        *aSlot = slotList->head->slot;      } else {        // Gerenate a list of slots and ask the user to choose //        tmpSlot = slotList->head;        while (tmpSlot) {            numSlots++;            tmpSlot = tmpSlot->next;        }        // Allocate the slot name buffer //        tokenNameList = NS_STATIC_CAST(PRUnichar**, nsMemory::Alloc(sizeof(PRUnichar *) * numSlots));        i = 0;        slotElement = PK11_GetFirstSafe(slotList);        while (slotElement) {			tokenNameList[i] = NS_ConvertUTF8toUCS2(PK11_GetTokenName(slotElement->slot)).ToNewUnicode();            slotElement = PK11_GetNextSafe(slotList, slotElement, PR_FALSE);            i++;        }		/* Throw up the token list dialog and get back the token */		rv = getNSSDialogs((void**)&dialogs,			               NS_GET_IID(nsITokenDialogs));		if (NS_FAILED(rv)) goto loser;		rv = dialogs->ChooseToken(nsnull, (const PRUnichar**)tokenNameList, numSlots, &unicodeTokenChosen, &canceled);		NS_RELEASE(dialogs);		if (NS_FAILED(rv)) goto loser;		if (canceled) { rv = NS_ERROR_NOT_AVAILABLE; goto loser; }        // Get the slot //        slotElement = PK11_GetFirstSafe(slotList);        nsAutoString tokenStr(unicodeTokenChosen);        while (slotElement) {            if (tokenStr.Equals(NS_ConvertUTF8toUCS2(PK11_GetTokenName(slotElement->slot)))) {                *aSlot = slotElement->slot;                break;            }            slotElement = PK11_GetNextSafe(slotList, slotElement, PR_FALSE);        }        if(!(*aSlot)) {            rv = NS_ERROR_FAILURE;            goto loser;        }      }      // Get a reference to the slot //      PK11_ReferenceSlot(*aSlot);loser:      if (slotList) {          PK11_FreeSlotList(slotList);      }      if (tokenNameList) {          nsMemory::Free(tokenNameList);      }      return rv;}