本文整理汇总了C++中PORT_Free函数的典型用法代码示例。如果您正苦于以下问题:C++ PORT_Free函数的具体用法?C++ PORT_Free怎么用?C++ PORT_Free使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PORT_Free函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PORT_NewArena
/********************* Arena code follows *****************************
* ArenaPools are like heaps. The memory in them consists of large blocks,
* called arenas, which are allocated from the/a system heap. Inside an
* ArenaPool, the arenas are organized as if they were in a stack. Newly
* allocated arenas are "pushed" on that stack. When you attempt to
* allocate memory from an ArenaPool, the code first looks to see if there
* is enough unused space in the top arena on the stack to satisfy your
* request, and if so, your request is satisfied from that arena.
* Otherwise, a new arena is allocated (or taken from NSPR's list of freed
* arenas) and pushed on to the stack. The new arena is always big enough
* to satisfy the request, and is also at least a minimum size that is
* established at the time that the ArenaPool is created.
*
* The ArenaMark function returns the address of a marker in the arena at
* the top of the arena stack. It is the address of the place in the arena
* on the top of the arena stack from which the next block of memory will
* be allocated. Each ArenaPool has its own separate stack, and hence
* marks are only relevant to the ArenaPool from which they are gotten.
* Marks may be nested. That is, a thread can get a mark, and then get
* another mark.
*
* It is intended that all the marks in an ArenaPool may only be owned by a
* single thread. In DEBUG builds, this is enforced. In non-DEBUG builds,
* it is not. In DEBUG builds, when a thread gets a mark from an
* ArenaPool, no other thread may acquire a mark in that ArenaPool while
* that mark exists, that is, until that mark is unmarked or released.
* Therefore, it is important that every mark be unmarked or released when
* the creating thread has no further need for exclusive ownership of the
* right to manage the ArenaPool.
*
* The ArenaUnmark function discards the ArenaMark at the address given,
* and all marks nested inside that mark (that is, acquired from that same
* ArenaPool while that mark existed). It is an error for a thread other
* than the mark's creator to try to unmark it. When a thread has unmarked
* all its marks from an ArenaPool, then another thread is able to set
* marks in that ArenaPool. ArenaUnmark does not deallocate (or "pop") any
* memory allocated from the ArenaPool since the mark was created.
*
* ArenaRelease "pops" the stack back to the mark, deallocating all the
* memory allocated from the arenas in the ArenaPool since that mark was
* created, and removing any arenas from the ArenaPool that have no
* remaining active allocations when that is done. It implicitly releases
* any marks nested inside the mark being explicitly released. It is the
* only operation, other than destroying the arenapool, that potentially
* reduces the number of arenas on the stack. Otherwise, the stack grows
* until the arenapool is destroyed, at which point all the arenas are
* freed or returned to a "free arena list", depending on their sizes.
*/
PLArenaPool *
PORT_NewArena(unsigned long chunksize)
{
PORTArenaPool *pool;
if (chunksize > MAX_SIZE) {
PORT_SetError(SEC_ERROR_NO_MEMORY);
return NULL;
}
pool = PORT_ZNew(PORTArenaPool);
if (!pool) {
return NULL;
}
pool->magic = ARENAPOOL_MAGIC;
pool->lock = PZ_NewLock(nssILockArena);
if (!pool->lock) {
PORT_Free(pool);
return NULL;
}
PL_InitArenaPool(&pool->arena, "security", chunksize, sizeof(double));
return (&pool->arena);
}
示例2: calculate_MD5_range
/*
* c a l c u l a t e _ M D 5 _ r a n g e
*
* Calculate the MD5 digest on a range of bytes in
* the specified fopen'd file. Returns base64.
*
*/
static int
calculate_MD5_range (FILE *fp, long r1, long r2, JAR_Digest *dig)
{
int num;
int range;
unsigned char *buf;
SECStatus rv;
range = r2 - r1;
/* position to the beginning of range */
fseek (fp, r1, SEEK_SET);
buf = (unsigned char *) PORT_ZAlloc (range);
if (buf == NULL)
out_of_memory();
if ((num = fread (buf, 1, range, fp)) != range) {
PR_fprintf(errorFD, "%s: expected %d bytes, got %d\n", PROGRAM_NAME,
range, num);
errorCount++;
exit (ERRX);
}
rv = PK11_HashBuf(SEC_OID_MD5, dig->md5, buf, range);
if (rv == SECSuccess) {
rv =PK11_HashBuf(SEC_OID_SHA1, dig->sha1, buf, range);
}
if (rv != SECSuccess) {
PR_fprintf(errorFD, "%s: can't generate digest context\n",
PROGRAM_NAME);
errorCount++;
exit (ERRX);
}
PORT_Free (buf);
return 0;
}
示例3: crmf_destroy_encrypted_key
static SECStatus
crmf_destroy_encrypted_key(CRMFEncryptedKey *inEncrKey, PRBool freeit)
{
PORT_Assert(inEncrKey != NULL);
if (inEncrKey != NULL) {
switch (inEncrKey->encKeyChoice){
case crmfEncryptedValueChoice:
crmf_destroy_encrypted_value(&inEncrKey->value.encryptedValue,
PR_FALSE);
break;
case crmfEnvelopedDataChoice:
SEC_PKCS7DestroyContentInfo(inEncrKey->value.envelopedData);
break;
default:
break;
}
if (freeit) {
PORT_Free(inEncrKey);
}
}
return SECSuccess;
}
示例4: SSL_GetNegotiatedHostInfo
SECItem*
SSL_GetNegotiatedHostInfo(PRFileDesc *fd)
{
SECItem *sniName = NULL;
sslSocket *ss;
char *name = NULL;
ss = ssl_FindSocket(fd);
if (!ss) {
SSL_DBG(("%d: SSL[%d]: bad socket in SSL_GetNegotiatedHostInfo",
SSL_GETPID(), fd));
return NULL;
}
if (ss->sec.isServer) {
if (ss->version > SSL_LIBRARY_VERSION_3_0 &&
ss->ssl3.initialized) { /* TLS */
SECItem *crsName;
ssl_GetSpecReadLock(ss); /*********************************/
crsName = &ss->ssl3.crSpec->srvVirtName;
if (crsName->data) {
sniName = SECITEM_DupItem(crsName);
}
ssl_ReleaseSpecReadLock(ss); /*----------------------------*/
}
return sniName;
}
name = SSL_RevealURL(fd);
if (name) {
sniName = PORT_ZNew(SECItem);
if (!sniName) {
PORT_Free(name);
return NULL;
}
sniName->data = (void*)name;
sniName->len = PORT_Strlen(name);
}
return sniName;
}
示例5: CERT_FindCRLDistributionPoints
CERTCrlDistributionPoints *
CERT_FindCRLDistributionPoints(CERTCertificate *cert)
{
SECItem encodedExtenValue;
SECStatus rv;
CERTCrlDistributionPoints *dps;
encodedExtenValue.data = NULL;
encodedExtenValue.len = 0;
rv = cert_FindExtension(cert->extensions, SEC_OID_X509_CRL_DIST_POINTS,
&encodedExtenValue);
if (rv != SECSuccess) {
return (NULL);
}
dps = CERT_DecodeCRLDistributionPoints(cert->arena, &encodedExtenValue);
PORT_Free(encodedExtenValue.data);
return dps;
}
示例6: secu_StdinToItem
SECStatus
secu_StdinToItem(SECItem *dst)
{
unsigned char buf[1000];
PRInt32 numBytes;
PRBool notDone = PR_TRUE;
dst->len = 0;
dst->data = NULL;
while (notDone) {
numBytes = PR_Read(PR_STDIN, buf, sizeof(buf));
if (numBytes < 0) {
return SECFailure;
}
if (numBytes == 0)
break;
if (dst->data) {
unsigned char *p = dst->data;
dst->data = (unsigned char *)PORT_Realloc(p, dst->len + numBytes);
if (!dst->data) {
PORT_Free(p);
}
} else {
dst->data = (unsigned char *)PORT_Alloc(numBytes);
}
if (!dst->data) {
return SECFailure;
}
PORT_Memcpy(dst->data + dst->len, buf, numBytes);
dst->len += numBytes;
}
return SECSuccess;
}
示例7: lg_OpenCertDB
static CK_RV
lg_OpenCertDB(const char * configdir, const char *prefix, PRBool readOnly,
NSSLOWCERTCertDBHandle **certdbPtr)
{
NSSLOWCERTCertDBHandle *certdb = NULL;
CK_RV crv = CKR_NETSCAPE_CERTDB_FAILED;
SECStatus rv;
char * name = NULL;
char * appName = NULL;
if (prefix == NULL) {
prefix = "";
}
configdir = lg_EvaluateConfigDir(configdir, &appName);
name = PR_smprintf("%s" PATH_SEPARATOR "%s",configdir,prefix);
if (name == NULL) goto loser;
certdb = (NSSLOWCERTCertDBHandle*)PORT_ZAlloc(sizeof(NSSLOWCERTCertDBHandle));
if (certdb == NULL)
goto loser;
certdb->ref = 1;
/* fix when we get the DB in */
rv = nsslowcert_OpenCertDB(certdb, readOnly, appName, prefix,
lg_certdb_name_cb, (void *)name, PR_FALSE);
if (rv == SECSuccess) {
crv = CKR_OK;
*certdbPtr = certdb;
certdb = NULL;
}
loser:
if (certdb) PR_Free(certdb);
if (name) PR_smprintf_free(name);
if (appName) PORT_Free(appName);
return crv;
}
示例8: GetCertFingerprintByOidTag
static nsresult
GetCertFingerprintByOidTag(CERTCertificate* nsscert,
SECOidTag aOidTag,
nsCString &fp)
{
unsigned int hash_len = HASH_ResultLenByOidTag(aOidTag);
nsStringBuffer* fingerprint = nsStringBuffer::Alloc(hash_len);
if (!fingerprint)
return NS_ERROR_OUT_OF_MEMORY;
PK11_HashBuf(aOidTag, (unsigned char*)fingerprint->Data(),
nsscert->derCert.data, nsscert->derCert.len);
SECItem fpItem;
fpItem.data = (unsigned char*)fingerprint->Data();
fpItem.len = hash_len;
char *tmpstr = CERT_Hexify(&fpItem, 1);
fp.Assign(tmpstr);
PORT_Free(tmpstr);
fingerprint->Release();
return NS_OK;
}
示例9: PORT_Strdup
static
char *sftk_getOldSecmodName(const char *dbname,const char *filename)
{
char *file = NULL;
char *dirPath = PORT_Strdup(dbname);
char *sep;
sep = PORT_Strrchr(dirPath,*PATH_SEPARATOR);
#ifdef _WIN32
if (!sep) {
/* pkcs11i.h defines PATH_SEPARATOR as "/" for all platforms. */
sep = PORT_Strrchr(dirPath,'\\');
}
#endif
if (sep) {
*sep = 0;
file = PR_smprintf("%s"PATH_SEPARATOR"%s", dirPath, filename);
} else {
file = PR_smprintf("%s", filename);
}
PORT_Free(dirPath);
return file;
}
示例10: SECITEM_ArenaDupItem
SecAsn1Item *
SECITEM_ArenaDupItem(PRArenaPool *arena, const SecAsn1Item *from)
{
SecAsn1Item *to;
if ( from == NULL ) {
return(NULL);
}
if ( arena != NULL ) {
to = (SecAsn1Item *)PORT_ArenaAlloc(arena, sizeof(SecAsn1Item));
} else {
to = (SecAsn1Item *)PORT_Alloc(sizeof(SecAsn1Item));
}
if ( to == NULL ) {
return(NULL);
}
if ( arena != NULL ) {
to->Data = (unsigned char *)PORT_ArenaAlloc(arena, from->Length);
} else {
to->Data = (unsigned char *)PORT_Alloc(from->Length);
}
if ( to->Data == NULL ) {
PORT_Free(to);
return(NULL);
}
to->Length = from->Length;
// to->type = from->type;
if ( to->Length ) {
PORT_Memcpy(to->Data, from->Data, to->Length);
}
return(to);
}
示例11: NS_ENSURE_ARG_POINTER
nsresult
nsClientAuthRememberService::RememberDecision(const nsACString & aHostName,
CERTCertificate *aServerCert, CERTCertificate *aClientCert)
{
// aClientCert == NULL means: remember that user does not want to use a cert
NS_ENSURE_ARG_POINTER(aServerCert);
if (aHostName.IsEmpty())
return NS_ERROR_INVALID_ARG;
nsCAutoString fpStr;
nsresult rv = GetCertFingerprintByOidTag(aServerCert, SEC_OID_SHA256, fpStr);
if (NS_FAILED(rv))
return rv;
{
nsAutoMonitor lock(monitor);
if (aClientCert) {
nsNSSCertificate pipCert(aClientCert);
char *dbkey = NULL;
rv = pipCert.GetDbKey(&dbkey);
if (NS_SUCCEEDED(rv) && dbkey) {
AddEntryToList(aHostName, fpStr,
nsDependentCString(dbkey));
}
if (dbkey) {
PORT_Free(dbkey);
}
}
else {
nsCString empty;
AddEntryToList(aHostName, fpStr, empty);
}
}
return NS_OK;
}
示例12: CERT_FindCertByNicknameOrEmailAddr
CERTCertificate *
CERT_FindCertByNicknameOrEmailAddr(CERTCertDBHandle *handle, const char *name)
{
NSSCryptoContext *cc;
NSSCertificate *c, *ct;
CERTCertificate *cert;
NSSUsage usage;
if (NULL == name) {
PORT_SetError(SEC_ERROR_INVALID_ARGS);
return NULL;
}
usage.anyUsage = PR_TRUE;
cc = STAN_GetDefaultCryptoContext();
ct = NSSCryptoContext_FindBestCertificateByNickname(cc, name,
NULL, &usage, NULL);
if (!ct && PORT_Strchr(name, '@') != NULL) {
char* lowercaseName = CERT_FixupEmailAddr(name);
if (lowercaseName) {
ct = NSSCryptoContext_FindBestCertificateByEmail(cc, lowercaseName,
NULL, &usage, NULL);
PORT_Free(lowercaseName);
}
}
cert = PK11_FindCertFromNickname(name, NULL);
if (cert) {
c = get_best_temp_or_perm(ct, STAN_GetNSSCertificate(cert));
CERT_DestroyCertificate(cert);
if (ct) {
CERT_DestroyCertificate(STAN_GetCERTCertificateOrRelease(ct));
}
} else {
c = ct;
}
return c ? STAN_GetCERTCertificateOrRelease(c) : NULL;
}
示例13: AddCertificateFromFile
SECStatus
AddCertificateFromFile(const char* basePath, const char* filename)
{
char buf[16384] = { 0 };
SECStatus rv = ReadFileToBuffer(basePath, filename, buf);
if (rv != SECSuccess) {
return rv;
}
SECItem certDER;
rv = CERT_DecodeCertPackage(buf, strlen(buf), DecodeCertCallback, &certDER);
if (rv != SECSuccess) {
PrintPRError("CERT_DecodeCertPackage failed");
return rv;
}
ScopedCERTCertificate cert(CERT_NewTempCertificate(CERT_GetDefaultCertDB(),
&certDER, nullptr, false,
true));
PORT_Free(certDER.data);
if (!cert) {
PrintPRError("CERT_NewTempCertificate failed");
return SECFailure;
}
ScopedPK11SlotInfo slot(PK11_GetInternalKeySlot());
if (!slot) {
PrintPRError("PK11_GetInternalKeySlot failed");
return SECFailure;
}
// The nickname is the filename without '.pem'.
std::string nickname(filename, strlen(filename) - 4);
rv = PK11_ImportCert(slot, cert, CK_INVALID_HANDLE, nickname.c_str(), false);
if (rv != SECSuccess) {
PrintPRError("PK11_ImportCert failed");
return rv;
}
return SECSuccess;
}
示例14: pkix_pl_LdapCertStore_DestroyAVAList
/*
* FUNCTION: pkix_pl_LdapCertStore_DestroyAVAList
* DESCRIPTION:
*
* This function frees the space allocated for the components of the
* equalFilters that make up the andFilter pointed to by "filter".
*
* PARAMETERS:
* "requestParams"
* The address of the andFilter whose components are to be freed. Must be
* non-NULL.
* "plContext"
* Platform-specific context pointer
* THREAD SAFETY:
* Thread Safe (see Thread Safety Definitions in Programmer's Guide)
* RETURNS:
* Returns NULL if the function succeeds.
* Returns a CertStore Error if the function fails in a non-fatal way.
* Returns a Fatal Error if the function fails in an unrecoverable way.
*/
static PKIX_Error *
pkix_pl_LdapCertStore_DestroyAVAList(
LDAPNameComponent **nameComponents,
void *plContext)
{
LDAPNameComponent **currentNC = NULL;
unsigned char *component = NULL;
PKIX_ENTER(CERTSTORE, "pkix_pl_LdapCertStore_DestroyAVAList");
PKIX_NULLCHECK_ONE(nameComponents);
/* Set currentNC to point to first AVA pointer */
currentNC = nameComponents;
while ((*currentNC) != NULL) {
component = (*currentNC)->attrValue;
if (component != NULL) {
PORT_Free(component);
}
currentNC++;
}
PKIX_RETURN(CERTSTORE);
}
示例15: AppendErrorTextMismatch
static void
AppendErrorTextMismatch(const nsString &host,
nsIX509Cert* ix509,
nsINSSComponent *component,
bool wantsHtml,
nsString &returnedMessage)
{
const char16_t *params[1];
nsresult rv;
ScopedCERTCertificate nssCert(ix509->GetCert());
if (!nssCert) {
// We are unable to extract the valid names, say "not valid for name".
params[0] = host.get();
nsString formattedString;
rv = component->PIPBundleFormatStringFromName("certErrorMismatch",
params, 1,
formattedString);
if (NS_SUCCEEDED(rv)) {
returnedMessage.Append(formattedString);
returnedMessage.Append('\n');
}
return;
}
nsString allNames;
uint32_t nameCount = 0;
bool useSAN = false;
if (nssCert)
useSAN = GetSubjectAltNames(nssCert.get(), component, allNames, nameCount);
if (!useSAN) {
char *certName = CERT_GetCommonName(&nssCert->subject);
if (certName) {
nsDependentCSubstring commonName(certName, strlen(certName));
if (IsUTF8(commonName)) {
// Bug 1024781
// We should actually check that the common name is a valid dns name or
// ip address and not any string value before adding it to the display
// list.
++nameCount;
allNames.Assign(NS_ConvertUTF8toUTF16(commonName));
}
PORT_Free(certName);
}
}
if (nameCount > 1) {
nsString message;
rv = component->GetPIPNSSBundleString("certErrorMismatchMultiple",
message);
if (NS_SUCCEEDED(rv)) {
returnedMessage.Append(message);
returnedMessage.AppendLiteral("\n ");
returnedMessage.Append(allNames);
returnedMessage.AppendLiteral(" \n");
}
}
else if (nameCount == 1) {
const char16_t *params[1];
params[0] = allNames.get();
const char *stringID;
if (wantsHtml)
stringID = "certErrorMismatchSingle2";
else
stringID = "certErrorMismatchSinglePlain";
nsString formattedString;
rv = component->PIPBundleFormatStringFromName(stringID,
params, 1,
formattedString);
if (NS_SUCCEEDED(rv)) {
returnedMessage.Append(formattedString);
returnedMessage.Append('\n');
}
}
else { // nameCount == 0
nsString message;
nsresult rv = component->GetPIPNSSBundleString("certErrorMismatchNoNames",
message);
if (NS_SUCCEEDED(rv)) {
returnedMessage.Append(message);
returnedMessage.Append('\n');
}
}
}