} return NULL; done: if (nicknameArena != NULL) { returnName =  PORT_ArenaStrdup(cert->arena, nickname); } else { returnName = PORT_Strdup(nickname); } if (arena != NULL) { PORT_FreeArena(arena, PR_FALSE); } PORT_Free(nickname);
if (basename) PORT_Free(basename); if (altNameExtension.data) PORT_Free(altNameExtension.data);
CERT_GetNickName(CERTCertificate   *cert, 		 CERTCertDBHandle  *handle,		 PRArenaPool      *nicknameArena){     CERTGeneralName  *current;    CERTGeneralName  *names;    SECItem          altNameExtension;    char             *nickname = NULL;    char             *returnName = NULL;    char             *tempname = NULL;    SECItem          *nick;    SECStatus        rv;    PRArenaPool      *arena = NULL;    int              count;    int              length;            if (handle == NULL) {	handle = CERT_GetDefaultCertDB();    }    rv = CERT_FindCertExtension(cert, SEC_OID_X509_SUBJECT_ALT_NAME, 				&altNameExtension);    if (rv != SECSuccess) { 	goto loser;     }    arena = PORT_NewArena(DER_DEFAULT_CHUNKSIZE);    if (arena == NULL) {	goto loser;    }    names = CERT_DecodeAltNameExtension(arena, &altNameExtension);    if (names == NULL) {	goto loser;    }     current = names;    do {	if (current->type == certOtherName && 	    SECOID_FindOIDTag(&current->name.OthName.oid) == SEC_OID_NETSCAPE_NICKNAME) {	    rv = SEC_ASN1DecodeItem(arena, nick, SEC_IA5StringTemplate, 				    &current->name.OthName.name);	    if (rv != SECSuccess) {		goto loser;	    }	    nickname = (char*)PORT_ZAlloc(nick->len + 1);	    if (nickname == NULL) {		goto loser;	    }	    nickname = PORT_Strncpy(nickname, (char *) nick->data, nick->len);	    length = nick->len;	    count = 1;	    tempname = nickname;	    while (CERT_FindCertByNickname(handle, nickname) != NULL) {		nickname = PR_smprintf("%s #%d", tempname, count);		count++;	    }	    goto done;	}	current = cert_get_next_general_name(current);    } while (current != names);loser:    if (arena != NULL) {	PORT_FreeArena(arena, PR_FALSE);    }    if (nickname != NULL) {	PORT_Free(nickname);    }    return NULL;done:    if (nicknameArena != NULL) {	returnName =  PORT_ArenaStrdup(cert->arena, nickname);    } else {	returnName = PORT_Strdup(nickname);    }    if (arena != NULL) {	PORT_FreeArena(arena, PR_FALSE);    }    PORT_Free(nickname);    return returnName;}