nickFmt = tmpNickFmt.ToNewUTF8String();
nickFmt = ToNewUTF8String(tmpNickFmt);
default_nickname(CERTCertificate *cert, nsIInterfaceRequestor* ctx){     nsresult rv;  char *username = NULL;  char *caname = NULL;  char *nickname = NULL;  char *tmp = NULL;  int count;  char *nickFmt=NULL, *nickFmtWithNum = NULL;  CERTCertificate *dummycert;  PK11SlotInfo *slot=NULL;  CK_OBJECT_HANDLE keyHandle;  nsAutoString tmpNickFmt;  nsAutoString tmpNickFmtWithNum;  CERTCertDBHandle *defaultcertdb = CERT_GetDefaultCertDB();  nsCOMPtr<nsINSSComponent> nssComponent(do_GetService(kNSSComponentCID, &rv));  if (NS_FAILED(rv)) goto loser;   username = CERT_GetCommonName(&cert->subject);  if ( username == NULL )     username = PL_strdup("");  if ( username == NULL )     goto loser;      caname = CERT_GetOrgName(&cert->issuer);  if ( caname == NULL )     caname = PL_strdup("");    if ( caname == NULL )     goto loser;    count = 1;  nssComponent->GetPIPNSSBundleString(                              NS_LITERAL_STRING("nick_template").get(),                              tmpNickFmt);  nickFmt = tmpNickFmt.ToNewUTF8String();  nssComponent->GetPIPNSSBundleString(                              NS_LITERAL_STRING("nick_template_with_num").get(),                              tmpNickFmtWithNum);  nickFmtWithNum = tmpNickFmtWithNum.ToNewUTF8String();  nickname = PR_smprintf(nickFmt, username, caname);  /*   * We need to see if the private key exists on a token, if it does   * then we need to check for nicknames that already exist on the smart   * card.   */  slot = PK11_KeyForCertExists(cert, &keyHandle, ctx);  if (slot == NULL) {    goto loser;  }  if (!PK11_IsInternal(slot)) {    tmp = PR_smprintf("%s:%s", PK11_GetTokenName(slot), nickname);    PR_Free(nickname);    nickname = tmp;    tmp = NULL;  }  tmp = nickname;  while ( 1 ) {	    if ( count > 1 ) {      nickname = PR_smprintf("%s #%d", tmp, count);    }      if ( nickname == NULL )       goto loser;     if (PK11_IsInternal(slot)) {      /* look up the nickname to make sure it isn't in use already */      dummycert = CERT_FindCertByNickname(defaultcertdb, nickname);          } else {      /*       * Check the cert against others that already live on the smart        * card.       */      dummycert = PK11_FindCertFromNickname(nickname, ctx);      if (dummycert != NULL) {	/*	 * Make sure the subject names are different.	 */ 	if (CERT_CompareName(&cert->subject, &dummycert->subject) == SECEqual)	{	  /*	   * There is another certificate with the same nickname and	   * the same subject name on the smart card, so let's use this	   * nickname.	   */	  CERT_DestroyCertificate(dummycert);	  dummycert = NULL;	}      }    }    if ( dummycert == NULL )       goto done;        /* found a cert, destroy it and loop */    CERT_DestroyCertificate(dummycert);    if (tmp != nickname) PR_Free(nickname);    count++;  } /* end of while(1) */    loser:  if ( nickname ) {    PR_Free(nickname);  }  nickname = NULL;done:  if ( caname ) {    PR_Free(caname);  }  if ( username )  {    PR_Free(username);  }  if (slot != NULL) {      PK11_FreeSlot(slot);      if (nickname != NULL) {	      tmp = nickname;	      nickname = strchr(tmp, ':');	      if (nickname != NULL) {	        nickname++;	        nickname = PL_strdup(nickname);	        PR_Free(tmp);             tmp = nsnull;	      } else {	        nickname = tmp;	        tmp = NULL;	      }      }    }    PR_FREEIF(tmp);    return(nickname);}