diff options
author | ian.mcgreer%sun.com <devnull@localhost> | 2001-11-29 19:34:08 +0000 |
---|---|---|
committer | ian.mcgreer%sun.com <devnull@localhost> | 2001-11-29 19:34:08 +0000 |
commit | 34b31464c1e923c469ea3ab03573c148eb9e86b5 (patch) | |
tree | 8ac3199329224290ffe549ac5e2e3e9ed3da14af /security | |
parent | 123670ab3df8dd84a0ade9007dbf3a1a81ddc29e (diff) | |
download | nss-hg-34b31464c1e923c469ea3ab03573c148eb9e86b5.tar.gz |
fix memory leaks
Diffstat (limited to 'security')
-rw-r--r-- | security/nss/lib/base/hash.c | 11 | ||||
-rw-r--r-- | security/nss/lib/base/list.c | 29 | ||||
-rw-r--r-- | security/nss/lib/nss/nssinit.c | 1 | ||||
-rw-r--r-- | security/nss/lib/pki/certdecode.c | 13 | ||||
-rw-r--r-- | security/nss/lib/pki/certificate.c | 7 | ||||
-rw-r--r-- | security/nss/lib/pki/cryptocontext.c | 6 | ||||
-rw-r--r-- | security/nss/lib/pki/pki3hack.c | 14 | ||||
-rw-r--r-- | security/nss/lib/pki/pki3hack.h | 7 | ||||
-rw-r--r-- | security/nss/lib/pki/pkim.h | 10 | ||||
-rw-r--r-- | security/nss/lib/pki/tdcache.c | 7 | ||||
-rw-r--r-- | security/nss/lib/pki/trustdomain.c | 2 |
11 files changed, 81 insertions, 26 deletions
diff --git a/security/nss/lib/base/hash.c b/security/nss/lib/base/hash.c index 39598ddd9..a8678d13e 100644 --- a/security/nss/lib/base/hash.c +++ b/security/nss/lib/base/hash.c @@ -64,6 +64,7 @@ static const char CVS_ID[] = "@(#) $RCSfile$ $Revision$ $Date$ $Name$"; struct nssHashStr { NSSArena *arena; + PRBool i_alloced_arena; PRLock *mutex; /* @@ -124,6 +125,7 @@ nssHash_Create { nssHash *rv; NSSArena *arena; + PRBool i_alloced; #ifdef NSSDEBUG if( arenaOpt && PR_SUCCESS != nssArena_verifyPointer(arenaOpt) ) { @@ -134,8 +136,10 @@ nssHash_Create if (arenaOpt) { arena = arenaOpt; + i_alloced = PR_FALSE; } else { arena = nssArena_Create(); + i_alloced = PR_TRUE; } rv = nss_ZNEW(arena, nssHash); @@ -157,9 +161,8 @@ nssHash_Create } rv->count = 0; - if (!arenaOpt) { - rv->arena = arena; - } + rv->arena = arena; + rv->i_alloced_arena = i_alloced; return rv; loser: @@ -224,7 +227,7 @@ nssHash_Destroy { (void)PZ_DestroyLock(hash->mutex); PL_HashTableDestroy(hash->plHashTable); - if (hash->arena) { + if (hash->i_alloced_arena) { nssArena_Destroy(hash->arena); } else { nss_ZFreeIf(hash); diff --git a/security/nss/lib/base/list.c b/security/nss/lib/base/list.c index 97eb874f8..1469f68d4 100644 --- a/security/nss/lib/base/list.c +++ b/security/nss/lib/base/list.c @@ -59,6 +59,7 @@ struct nssListStr { PRUint32 count; nssListCompareFunc compareFunc; nssListSortFunc sortFunc; + PRBool i_alloced_arena; }; struct nssListIteratorStr { @@ -109,7 +110,14 @@ nssList_Create { NSSArena *arena; nssList *list; - arena = (arenaOpt) ? arenaOpt : nssArena_Create(); + PRBool i_alloced; + if (arenaOpt) { + arena = arenaOpt; + i_alloced = PR_FALSE; + } else { + arena = nssArena_Create(); + i_alloced = PR_TRUE; + } if (!arena) { return (nssList *)NULL; } @@ -128,9 +136,8 @@ nssList_Create return (nssList *)NULL; } } - if (!arenaOpt) { - list->arena = arena; - } + list->arena = arena; + list->i_alloced_arena = i_alloced; list->compareFunc = pointer_compare; return list; } @@ -138,15 +145,15 @@ nssList_Create NSS_IMPLEMENT PRStatus nssList_Destroy(nssList *list) { - PZLock *lock = list->lock; - if (list->arena) { - NSSArena_Destroy(list->arena); - list = NULL; - } else { + if (!list->i_alloced_arena) { nssList_Clear(list, NULL); } - if (lock) { - PZ_DestroyLock(lock); + if (list->lock) { + (void)PZ_DestroyLock(list->lock); + } + if (list->i_alloced_arena) { + NSSArena_Destroy(list->arena); + list = NULL; } nss_ZFreeIf(list); return PR_SUCCESS; diff --git a/security/nss/lib/nss/nssinit.c b/security/nss/lib/nss/nssinit.c index e43f4ac61..82e762871 100644 --- a/security/nss/lib/nss/nssinit.c +++ b/security/nss/lib/nss/nssinit.c @@ -388,6 +388,7 @@ NSS_Shutdown(void) isInitialized = PR_FALSE; #endif + STAN_Shutdown(); } diff --git a/security/nss/lib/pki/certdecode.c b/security/nss/lib/pki/certdecode.c index deccb57ce..0182216ee 100644 --- a/security/nss/lib/pki/certdecode.c +++ b/security/nss/lib/pki/certdecode.c @@ -43,6 +43,19 @@ static const char CVS_ID[] = "@(#) $RCSfile$ $Revision$ $Date$ $Name$"; #include "pkim.h" #endif /* PKIM_H */ +/* XXX + * move this to a more appropriate location + */ +NSS_IMPLEMENT PRStatus +nssPKIObject_Destroy +( + nssPKIObject *object +) +{ + nssList_Destroy(object->instanceList); + nssArena_Destroy(object->arena); +} + #ifdef NSS_3_4_CODE /* This is defined in nss3hack.c */ NSS_EXTERN nssDecodedCert * diff --git a/security/nss/lib/pki/certificate.c b/security/nss/lib/pki/certificate.c index 152931fc4..b1fe10885 100644 --- a/security/nss/lib/pki/certificate.c +++ b/security/nss/lib/pki/certificate.c @@ -85,10 +85,10 @@ NSSCertificate_Destroy ) { #ifdef NSS_3_4_CODE - return NSSArena_Destroy(c->object.arena); + return nssPKIObject_Destroy(&c->object); #else if (--c->refCount == 0) { - return NSSArena_Destroy(c->arena); + return nssPKIObject_Destroy(&c->object); } #endif return PR_SUCCESS; @@ -187,7 +187,8 @@ nssCertificate_GetDecoding ) { if (!c->decoding) { - c->decoding = nssDecodedCert_Create(NULL, &c->encoding, c->type); + c->decoding = nssDecodedCert_Create(c->object.arena, + &c->encoding, c->type); } return c->decoding; } diff --git a/security/nss/lib/pki/cryptocontext.c b/security/nss/lib/pki/cryptocontext.c index 9460ed1c1..bd10ad80e 100644 --- a/security/nss/lib/pki/cryptocontext.c +++ b/security/nss/lib/pki/cryptocontext.c @@ -57,11 +57,11 @@ extern const NSSError NSS_ERROR_NOT_FOUND; NSS_IMPLEMENT PRStatus NSSCryptoContext_Destroy ( - NSSCryptoContext *td + NSSCryptoContext *cc ) { - nss_SetError(NSS_ERROR_NOT_FOUND); - return PR_FAILURE; + nssArena_Destroy(cc->arena); + return PR_SUCCESS; } NSS_IMPLEMENT PRStatus diff --git a/security/nss/lib/pki/pki3hack.c b/security/nss/lib/pki/pki3hack.c index 69d54e8ce..c7d39561e 100644 --- a/security/nss/lib/pki/pki3hack.c +++ b/security/nss/lib/pki/pki3hack.c @@ -110,6 +110,17 @@ STAN_LoadDefaultNSS3TrustDomain g_default_crypto_context = NSSTrustDomain_CreateCryptoContext(td, NULL); } +NSS_IMPLEMENT void +STAN_Shutdown() +{ + if (g_default_trust_domain) { + NSSTrustDomain_Destroy(g_default_trust_domain); + } + if (g_default_crypto_context) { + NSSCryptoContext_Destroy(g_default_crypto_context); + } +} + NSS_IMPLEMENT PRStatus STAN_AddNewSlotToDefaultTD ( @@ -386,6 +397,7 @@ nssTrust_GetCERTCertTrustForCert(NSSCertificate *c, NSSToken *token, rvTrust->emailFlags |= CERTDB_USER; rvTrust->objectSigningFlags |= CERTDB_USER; } + (void)nssPKIObject_Destroy(&t->object); return rvTrust; } @@ -567,7 +579,7 @@ STAN_ChangeCertTrust(CERTCertificate *cc, CERTCertTrust *trust) /* maybe GetDefaultTrustToken()? */ nssrv = nssToken_ImportTrust(instance->cryptoki.token, NULL, &nssTrust, instance->trustDomain, instance->cryptoContext); - nssArena_Destroy(nssTrust.object.arena); + (void)nssPKIObject_Destroy(&nssTrust.object); return nssrv; } diff --git a/security/nss/lib/pki/pki3hack.h b/security/nss/lib/pki/pki3hack.h index 8acb34b4c..1472c2ae0 100644 --- a/security/nss/lib/pki/pki3hack.h +++ b/security/nss/lib/pki/pki3hack.h @@ -57,15 +57,18 @@ PR_BEGIN_EXTERN_C NSS_EXTERN NSSTrustDomain * STAN_GetDefaultTrustDomain(); -NSSCryptoContext * +NSS_EXTERN NSSCryptoContext * STAN_GetDefaultCryptoContext(); -NSS_IMPLEMENT void +NSS_EXTERN void STAN_LoadDefaultNSS3TrustDomain ( void ); +NSS_EXTERN void +STAN_Shutdown(); + NSS_EXTERN PRStatus STAN_AddNewSlotToDefaultTD ( diff --git a/security/nss/lib/pki/pkim.h b/security/nss/lib/pki/pkim.h index 192682720..5f2651f86 100644 --- a/security/nss/lib/pki/pkim.h +++ b/security/nss/lib/pki/pkim.h @@ -232,7 +232,7 @@ nssCertificate_GetDecoding NSSCertificate *c ); -NSS_IMPLEMENT nssDecodedCert * +NSS_EXTERN nssDecodedCert * nssDecodedCert_Create ( NSSArena *arenaOpt, @@ -240,12 +240,18 @@ nssDecodedCert_Create NSSCertificateType type ); -NSS_IMPLEMENT PRStatus +NSS_EXTERN PRStatus nssDecodedCert_Destroy ( nssDecodedCert *dc ); +NSS_EXTERN PRStatus +nssPKIObject_Destroy +( + nssPKIObject *object +); + NSS_EXTERN NSSTime * NSSTime_Now ( diff --git a/security/nss/lib/pki/tdcache.c b/security/nss/lib/pki/tdcache.c index 5d987ea75..cc4612f41 100644 --- a/security/nss/lib/pki/tdcache.c +++ b/security/nss/lib/pki/tdcache.c @@ -247,7 +247,14 @@ nssTrustDomain_DestroyCache NSSTrustDomain *td ) { + if (!td->cache) { + return PR_FAILURE; + } PZ_DestroyLock(td->cache->lock); + nssHash_Destroy(td->cache->issuerAndSN); + nssHash_Destroy(td->cache->subject); + nssHash_Destroy(td->cache->nickname); + nssHash_Destroy(td->cache->email); nssArena_Destroy(td->cache->arena); td->cache = NULL; #ifdef DEBUG_CACHE diff --git a/security/nss/lib/pki/trustdomain.c b/security/nss/lib/pki/trustdomain.c index 0cbf021a9..17d17874e 100644 --- a/security/nss/lib/pki/trustdomain.c +++ b/security/nss/lib/pki/trustdomain.c @@ -117,6 +117,7 @@ NSSTrustDomain_Destroy nssList_Clear(td->tokenList, token_destructor); nssList_Destroy(td->tokenList); } + nssTrustDomain_DestroyCache(td); /* Destroy the trust domain */ nssArena_Destroy(td->arena); } @@ -982,6 +983,7 @@ NSSTrustDomain_CreateCryptoContext return NULL; } rvCC->td = td; + rvCC->arena = arena; return rvCC; } |