Moving leak fixes from logging_102900_branch to trunk to quite tinderbox a bit more.

This commit is contained in:
warren%netscape.com 2000-11-01 01:41:15 +00:00
parent c8d1c1d0bb
commit 48f769ea63
2 changed files with 47 additions and 8 deletions

View File

@ -62,7 +62,9 @@ nsLoggingService::nsLoggingService()
nsLoggingService::~nsLoggingService()
{
#ifdef DEBUG_warren
DescribeLogs(LogInfo);
#endif
}
NS_IMPL_QUERY_INTERFACE1(nsLoggingService, nsILoggingService)
@ -380,7 +382,33 @@ nsLog::~nsLog()
if (mName) nsCRT::free(mName);
}
NS_IMPL_ISUPPORTS1(nsLog, nsILog)
// !!! We don't use NS_IMPL_ISUPPORTS for nsLog because logs always appear to
// leak due to the way NS_IMPL_LOG works.
NS_IMETHODIMP_(nsrefcnt)
nsLog::AddRef(void)
{
NS_PRECONDITION(PRInt32(mRefCnt) >= 0, "illegal refcnt");
NS_ASSERT_OWNINGTHREAD(nsLog);
++mRefCnt;
return mRefCnt;
}
NS_IMETHODIMP_(nsrefcnt)
nsLog::Release(void)
{
NS_PRECONDITION(0 != mRefCnt, "dup release");
NS_ASSERT_OWNINGTHREAD(nsLog);
--mRefCnt;
if (mRefCnt == 0) {
mRefCnt = 1; /* stabilize */
NS_DELETEXPCOM(this);
return 0;
}
return mRefCnt;
}
NS_IMPL_QUERY_INTERFACE1(nsLog, nsILog)
nsresult
nsLog::Init(const char* name, PRUint32 controlFlags, nsILogEventSink* sink)
@ -534,9 +562,9 @@ nsLog::Printf(const char* format, ...)
va_list args;
va_start(args, format);
const char* msg = PR_vsmprintf(format, args);
nsresult rv = Vprintf(format, args);
va_end(args);
return mSink->Print(this, msg);
return rv;
}
NS_IMETHODIMP
@ -544,8 +572,11 @@ nsLog::Vprintf(const char* format, va_list args)
{
nsAutoMonitor monitor(gLogMonitor);
const char* msg = PR_vsmprintf(format, args);
return mSink->Print(this, msg);
char* msg = PR_vsmprintf(format, args);
if (!msg) return NS_ERROR_OUT_OF_MEMORY;
nsresult rv = mSink->Print(this, msg);
PR_smprintf_free(msg);
return rv;
}
////////////////////////////////////////////////////////////////////////////////
@ -721,4 +752,12 @@ nsFileLogEventSink::Flush(nsILog* log)
////////////////////////////////////////////////////////////////////////////////
#else
PR_IMPLEMENT(nsILog*)
NS_GetLog(const char* name, PRUint32 controlFlags)
{
return nsnull;
}
#endif // NS_ENABLE_LOGGING

View File

@ -31,8 +31,8 @@
* - isn't scriptable,
* - can't control printing format, including indentation,
* - it's ugly.
* We've solved these problems with NS_LOG, the new modern equivalent. Here's
* how you use it:
* We've solved these problems with xpcom logging facility, nslog, the new modern
* equivalent. Here's how you use it:
*
* #include "nslog.h"
*
@ -55,7 +55,7 @@
* a33e50 Foo hello world 42
*
* The hex number at the beginning of the line indicates the ID of the thread
* executing the NS_LOG statement. The name of the log appears next.
* executing the PRINTF statement. The name of the log appears next.
*
* A cool feature of how these macros work is that when NS_DISABLE_LOGGING is
* defined, all the logging code macro-expands to nothing.