if(slot) { PK11_FreeSlot(slot); }
Java_org_mozilla_jss_CryptoManager_findCertsByNicknameNative  (JNIEnv *env, jobject this, jstring nickname){    CERTCertList *list =NULL;    jobjectArray certArray=NULL;    CERTCertListNode *node;    const char *nickChars=NULL;    jboolean charsAreCopied;    jclass certClass;    int count;    int i;    /* convert the nickname string */    nickChars = (*env)->GetStringUTFChars(env, nickname, &charsAreCopied);    if( nickChars == NULL ) {        goto finish;    }    /* get the list of certs with the given nickname */    list = PK11_FindCertsFromNickname( (char*)nickChars, NULL /*wincx*/);    if( list == NULL ) {        count = 0;    } else {        /* Since this structure changed in NSS_2_7_RTM (the reference */        /* to "count" was removed from the "list" structure) we must  */        /* now count up the number of nodes manually!                 */        for( node = CERT_LIST_HEAD(list), count=0;             ! CERT_LIST_END(node, list);             node = CERT_LIST_NEXT(node), count++ );    }    PR_ASSERT(count >= 0);    /* create the cert array */    certClass = (*env)->FindClass(env, X509_CERT_CLASS);    if( certClass == NULL ) {        goto finish;    }    certArray = (*env)->NewObjectArray(env, count, certClass, NULL);    if( certArray == NULL ) {        /* exception was thrown */        goto finish;    }    if( list == NULL ) {        goto finish;    }    /* traverse the list, placing each cert into the array */    for(    node = CERT_LIST_HEAD(list), i=0;            ! CERT_LIST_END(node, list);            node = CERT_LIST_NEXT(node), i++       )     {        CERTCertificate *cert;        jobject certObj;        /* Create a Java certificate object from the current CERTCertificate */        cert = CERT_DupCertificate(node->cert);        certObj = JSS_PK11_wrapCert(env, &cert);        if( certObj == NULL ) {            goto finish;        }        /* put the Java certificate into the next element in the array */        (*env)->SetObjectArrayElement(env, certArray, i, certObj);        if( (*env)->ExceptionOccurred(env) ) {            goto finish;        }    }    /* sanity check */    PR_ASSERT( i == count );finish:    if(list) {        CERT_DestroyCertList(list);    }    if( nickChars && charsAreCopied ) {        (*env)->ReleaseStringUTFChars(env, nickname, nickChars);    }    return certArray;}