fix memory leaks

This commit is contained in:
ian.mcgreer%sun.com 2001-11-29 19:34:08 +00:00
parent 080d89f1d8
commit 054d08b4cd
11 changed files with 92 additions and 37 deletions

View File

@ -32,7 +32,7 @@
*/
#ifdef DEBUG
static const char CVS_ID[] = "@(#) $RCSfile: hash.c,v $ $Revision: 1.4 $ $Date: 2001/11/28 16:23:34 $ $Name: $";
static const char CVS_ID[] = "@(#) $RCSfile: hash.c,v $ $Revision: 1.5 $ $Date: 2001/11/29 19:33:59 $ $Name: $";
#endif /* DEBUG */
/*
@ -64,6 +64,7 @@ static const char CVS_ID[] = "@(#) $RCSfile: hash.c,v $ $Revision: 1.4 $ $Date:
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->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);

View File

@ -32,7 +32,7 @@
*/
#ifdef DEBUG
static const char CVS_ID[] = "@(#) $RCSfile: list.c,v $ $Revision: 1.8 $ $Date: 2001/11/28 16:23:35 $ $Name: $";
static const char CVS_ID[] = "@(#) $RCSfile: list.c,v $ $Revision: 1.9 $ $Date: 2001/11/29 19:34:00 $ $Name: $";
#endif /* DEBUG */
/*
@ -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->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;

View File

@ -32,7 +32,7 @@
* may use your version of this file under either the MPL or the
* GPL.
*
# $Id: nssinit.c,v 1.29 2001/11/20 18:28:41 relyea%netscape.com Exp $
# $Id: nssinit.c,v 1.30 2001/11/29 19:34:03 ian.mcgreer%sun.com Exp $
*/
#include <ctype.h>
@ -388,6 +388,7 @@ NSS_Shutdown(void)
isInitialized = PR_FALSE;
#endif
STAN_Shutdown();
}

View File

@ -32,7 +32,7 @@
*/
#ifdef DEBUG
static const char CVS_ID[] = "@(#) $RCSfile: certdecode.c,v $ $Revision: 1.3 $ $Date: 2001/11/08 00:15:19 $ $Name: $";
static const char CVS_ID[] = "@(#) $RCSfile: certdecode.c,v $ $Revision: 1.4 $ $Date: 2001/11/29 19:34:06 $ $Name: $";
#endif /* DEBUG */
#ifndef PKIT_H
@ -43,6 +43,19 @@ static const char CVS_ID[] = "@(#) $RCSfile: certdecode.c,v $ $Revision: 1.3 $ $
#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 *

View File

@ -32,7 +32,7 @@
*/
#ifdef DEBUG
static const char CVS_ID[] = "@(#) $RCSfile: certificate.c,v $ $Revision: 1.17 $ $Date: 2001/11/28 16:23:43 $ $Name: $";
static const char CVS_ID[] = "@(#) $RCSfile: certificate.c,v $ $Revision: 1.18 $ $Date: 2001/11/29 19:34:06 $ $Name: $";
#endif /* DEBUG */
#ifndef NSSPKI_H
@ -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;
}

View File

@ -32,7 +32,7 @@
*/
#ifdef DEBUG
static const char CVS_ID[] = "@(#) $RCSfile: cryptocontext.c,v $ $Revision: 1.5 $ $Date: 2001/11/28 16:23:43 $ $Name: $";
static const char CVS_ID[] = "@(#) $RCSfile: cryptocontext.c,v $ $Revision: 1.6 $ $Date: 2001/11/29 19:34:06 $ $Name: $";
#endif /* DEBUG */
#ifndef NSSPKI_H
@ -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

View File

@ -32,7 +32,7 @@
*/
#ifdef DEBUG
static const char CVS_ID[] = "@(#) $RCSfile: pki3hack.c,v $ $Revision: 1.5 $ $Date: 2001/11/28 16:23:43 $ $Name: $";
static const char CVS_ID[] = "@(#) $RCSfile: pki3hack.c,v $ $Revision: 1.6 $ $Date: 2001/11/29 19:34:06 $ $Name: $";
#endif /* DEBUG */
/*
@ -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;
}

View File

@ -35,7 +35,7 @@
#define PKINSS3HACK_H
#ifdef DEBUG
static const char PKINSS3HACK_CVS_ID[] = "@(#) $RCSfile: pki3hack.h,v $ $Revision: 1.2 $ $Date: 2001/11/28 16:23:43 $ $Name: $";
static const char PKINSS3HACK_CVS_ID[] = "@(#) $RCSfile: pki3hack.h,v $ $Revision: 1.3 $ $Date: 2001/11/29 19:34:06 $ $Name: $";
#endif /* DEBUG */
#ifndef NSSPKIT_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
(

View File

@ -35,7 +35,7 @@
#define PKIM_H
#ifdef DEBUG
static const char PKIM_CVS_ID[] = "@(#) $RCSfile: pkim.h,v $ $Revision: 1.7 $ $Date: 2001/11/28 16:23:43 $ $Name: $";
static const char PKIM_CVS_ID[] = "@(#) $RCSfile: pkim.h,v $ $Revision: 1.8 $ $Date: 2001/11/29 19:34:07 $ $Name: $";
#endif /* DEBUG */
#ifndef BASE_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
(

View File

@ -32,7 +32,7 @@
*/
#ifdef DEBUG
static const char CVS_ID[] = "@(#) $RCSfile: tdcache.c,v $ $Revision: 1.11 $ $Date: 2001/11/28 20:19:38 $ $Name: $";
static const char CVS_ID[] = "@(#) $RCSfile: tdcache.c,v $ $Revision: 1.12 $ $Date: 2001/11/29 19:34:07 $ $Name: $";
#endif /* DEBUG */
#ifndef PKIM_H
@ -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

View File

@ -32,7 +32,7 @@
*/
#ifdef DEBUG
static const char CVS_ID[] = "@(#) $RCSfile: trustdomain.c,v $ $Revision: 1.17 $ $Date: 2001/11/28 16:23:44 $ $Name: $";
static const char CVS_ID[] = "@(#) $RCSfile: trustdomain.c,v $ $Revision: 1.18 $ $Date: 2001/11/29 19:34:08 $ $Name: $";
#endif /* DEBUG */
#ifndef NSSPKI_H
@ -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;
}