From 52654fad566cdbc933dcadb366866c3639f17635 Mon Sep 17 00:00:00 2001 From: "wtc%google.com" Date: Sat, 10 May 2008 01:03:18 +0000 Subject: [PATCH] Bug 431805: fixed the leak of the primordial thread's error stack. The patch is contributed by Boying Lu . r=wtc. Modified files: base/base.h base/error.c nss/nssinit.c --- security/nss/lib/base/base.h | 14 +++++++++++++- security/nss/lib/base/error.c | 17 ++++++++++++++++- security/nss/lib/nss/nssinit.c | 10 +++++++++- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/security/nss/lib/base/base.h b/security/nss/lib/base/base.h index a18d6ef14e0..15532f364cf 100644 --- a/security/nss/lib/base/base.h +++ b/security/nss/lib/base/base.h @@ -38,7 +38,7 @@ #define BASE_H #ifdef DEBUG -static const char BASE_CVS_ID[] = "@(#) $RCSfile: base.h,v $ $Revision: 1.19 $ $Date: 2008-02-23 05:29:23 $"; +static const char BASE_CVS_ID[] = "@(#) $RCSfile: base.h,v $ $Revision: 1.20 $ $Date: 2008-05-10 01:03:14 $"; #endif /* DEBUG */ /* @@ -574,6 +574,18 @@ nss_ClearErrorStack void ); +/* + * nss_DestroyErrorStack + * + * This routine frees the calling thread's error stack. + */ + +NSS_EXTERN void +nss_DestroyErrorStack +( + void +); + /* * NSSItem * diff --git a/security/nss/lib/base/error.c b/security/nss/lib/base/error.c index e5036ad5021..c39a8648b84 100644 --- a/security/nss/lib/base/error.c +++ b/security/nss/lib/base/error.c @@ -35,7 +35,7 @@ * ***** END LICENSE BLOCK ***** */ #ifdef DEBUG -static const char CVS_ID[] = "@(#) $RCSfile: error.c,v $ $Revision: 1.7 $ $Date: 2005-12-19 17:53:28 $"; +static const char CVS_ID[] = "@(#) $RCSfile: error.c,v $ $Revision: 1.8 $ $Date: 2008-05-10 01:03:15 $"; #endif /* DEBUG */ /* @@ -284,3 +284,18 @@ nss_ClearErrorStack ( void) es->stack[0] = 0; return; } + +/* + * nss_DestroyErrorStack + * + * This routine frees the calling thread's error stack. + */ + +NSS_IMPLEMENT void +nss_DestroyErrorStack ( void) +{ + if( 0 != error_stack_index ) { + PR_SetThreadPrivate(error_stack_index, NULL); + } + return; +} diff --git a/security/nss/lib/nss/nssinit.c b/security/nss/lib/nss/nssinit.c index 53fd7cc04f4..26893eeecbf 100644 --- a/security/nss/lib/nss/nssinit.c +++ b/security/nss/lib/nss/nssinit.c @@ -36,7 +36,7 @@ * the terms of any one of the MPL, the GPL or the LGPL. * * ***** END LICENSE BLOCK ***** */ -/* $Id: nssinit.c,v 1.94 2008-03-26 18:49:04 alexei.volkov.bugs%sun.com Exp $ */ +/* $Id: nssinit.c,v 1.95 2008-05-10 01:03:18 wtc%google.com Exp $ */ #include #include "seccomon.h" @@ -898,6 +898,14 @@ NSS_Shutdown(void) shutdownRV = SECFailure; } pk11sdr_Shutdown(); + /* + * A thread's error stack is automatically destroyed when the thread + * terminates except for the primordial thread, which must call + * PR_Cleanup. Since NSS is usually initialized by the primordial + * thread, and many NSS-based apps don't call PR_Cleanup, we destroy + * the error stack here. + */ + nss_DestroyErrorStack(); nssArena_Shutdown(); if (status == PR_FAILURE) { if (NSS_GetError() == NSS_ERROR_BUSY) {