Added a -x option to viewer to allow us to test for shutdown leaks. Eliminated leaks.

This commit is contained in:
warren%netscape.com 1999-09-17 21:00:54 +00:00
Родитель cbf2204bfc
Коммит aac2ad9fe7
3 изменённых файлов: 32 добавлений и 16 удалений

Просмотреть файл

@ -117,6 +117,7 @@ nsViewerApp::nsViewerApp()
mIsInitialized = PR_FALSE; mIsInitialized = PR_FALSE;
mWidth = DEFAULT_WIDTH; mWidth = DEFAULT_WIDTH;
mHeight = DEFAULT_HEIGHT; mHeight = DEFAULT_HEIGHT;
mJustShutdown = PR_FALSE;
} }
nsViewerApp::~nsViewerApp() nsViewerApp::~nsViewerApp()
@ -208,9 +209,11 @@ nsViewerApp::SetupRegistry()
nsIFactory* bwf; nsIFactory* bwf;
NS_NewBrowserWindowFactory(&bwf); NS_NewBrowserWindowFactory(&bwf);
nsComponentManager::RegisterFactory(kBrowserWindowCID, 0, 0, bwf, PR_FALSE); nsComponentManager::RegisterFactory(kBrowserWindowCID, 0, 0, bwf, PR_FALSE);
NS_RELEASE(bwf);
NS_NewXPBaseWindowFactory(&bwf); NS_NewXPBaseWindowFactory(&bwf);
nsComponentManager::RegisterFactory(kXPBaseWindowCID, 0, 0, bwf, PR_FALSE); nsComponentManager::RegisterFactory(kXPBaseWindowCID, 0, 0, bwf, PR_FALSE);
NS_RELEASE(bwf);
return NS_OK; return NS_OK;
} }
@ -243,7 +246,7 @@ nsViewerApp::Initialize(int argc, char** argv)
// Create widget application shell // Create widget application shell
rv = nsComponentManager::CreateInstance(kAppShellCID, nsnull, kIAppShellIID, rv = nsComponentManager::CreateInstance(kAppShellCID, nsnull, kIAppShellIID,
(void**)&mAppShell); (void**)&mAppShell);
if (NS_OK != rv) { if (NS_OK != rv) {
return rv; return rv;
} }
@ -252,7 +255,7 @@ nsViewerApp::Initialize(int argc, char** argv)
// Load preferences // Load preferences
rv = nsComponentManager::CreateInstance(kPrefCID, NULL, kIPrefIID, rv = nsComponentManager::CreateInstance(kPrefCID, NULL, kIPrefIID,
(void **) &mPrefs); (void **) &mPrefs);
if (NS_OK != rv) { if (NS_OK != rv) {
return rv; return rv;
} }
@ -318,16 +321,21 @@ nsViewerApp::Initialize(int argc, char** argv)
nsresult nsresult
nsViewerApp::Exit() nsViewerApp::Exit()
{ {
nsresult rv = NS_OK;
Destroy(); if (mAppShell) {
mAppShell->Exit(); Destroy();
NS_RELEASE(mAppShell); mAppShell->Exit();
NS_RELEASE(mAppShell);
if (nsnull != mEventQService) {
nsServiceManager::ReleaseService(kEventQueueServiceCID, mEventQService);
mEventQService = nsnull;
} }
return NS_OK; if (mEventQService) {
printf("Going to destroy the event queue\n");
rv = mEventQService->DestroyThreadEventQueue();
if (nsnull != mEventQService) {
nsServiceManager::ReleaseService(kEventQueueServiceCID, mEventQService);
mEventQService = nsnull;
}
}
return rv;
} }
static void static void
@ -351,6 +359,7 @@ PrintHelpInfo(char **argv)
fprintf(stderr, "-S domain -- add a domain/host that is safe to crawl (e.g. www.netscape.com)\n"); fprintf(stderr, "-S domain -- add a domain/host that is safe to crawl (e.g. www.netscape.com)\n");
fprintf(stderr, "-A domain -- add a domain/host that should be avoided (e.g. microsoft.com)\n"); fprintf(stderr, "-A domain -- add a domain/host that should be avoided (e.g. microsoft.com)\n");
fprintf(stderr, "-N pages -- set the max # of pages to crawl\n"); fprintf(stderr, "-N pages -- set the max # of pages to crawl\n");
fprintf(stderr, "-x -- startup and just shutdown to test for leaks under Purify\n");
#if defined(NS_DEBUG) && defined(XP_WIN) #if defined(NS_DEBUG) && defined(XP_WIN)
fprintf(stderr, "-md # -- set the crt debug flags to #\n"); fprintf(stderr, "-md # -- set the crt debug flags to #\n");
#endif #endif
@ -415,15 +424,17 @@ nsViewerApp::ProcessArguments(int argc, char** argv)
int i; int i;
for (i = 1; i < argc; i++) { for (i = 1; i < argc; i++) {
if (argv[i][0] == '-') { if (argv[i][0] == '-') {
if (PL_strcmp(argv[i], "-x") == 0) {
mJustShutdown = PR_TRUE;
}
#if defined(NS_DEBUG) && defined(XP_WIN) #if defined(NS_DEBUG) && defined(XP_WIN)
if (PL_strcmp(argv[i], "-md") == 0) { else if (PL_strcmp(argv[i], "-md") == 0) {
int old = _CrtSetDbgFlag(0); int old = _CrtSetDbgFlag(0);
old |= _CRTDBG_CHECK_ALWAYS_DF; old |= _CRTDBG_CHECK_ALWAYS_DF;
_CrtSetDbgFlag(old); _CrtSetDbgFlag(old);
} }
else
#endif #endif
if (PL_strncmp(argv[i], "-p", 2) == 0) { else if (PL_strncmp(argv[i], "-p", 2) == 0) {
char *optionalSampleStopIndex = &(argv[i][2]); char *optionalSampleStopIndex = &(argv[i][2]);
if ('\0' != *optionalSampleStopIndex) if ('\0' != *optionalSampleStopIndex)
{ {

Просмотреть файл

@ -82,6 +82,7 @@ protected:
PRBool mIsInitialized; PRBool mIsInitialized;
PRInt32 mWidth, mHeight; PRInt32 mWidth, mHeight;
PRBool mShowLoadTimes; PRBool mShowLoadTimes;
PRBool mJustShutdown;
}; };
class nsNativeViewerApp : public nsViewerApp { class nsNativeViewerApp : public nsViewerApp {

Просмотреть файл

@ -39,6 +39,9 @@ nsNativeViewerApp::~nsNativeViewerApp()
int int
nsNativeViewerApp::Run() nsNativeViewerApp::Run()
{ {
if (mJustShutdown)
return 0;
OpenWindow(); OpenWindow();
// Process messages // Process messages
@ -47,7 +50,7 @@ nsNativeViewerApp::Run()
// Pump all messages // Pump all messages
do { do {
BOOL havePriorityMessage; // BOOL havePriorityMessage;
// Give priority to system messages (in particular keyboard, mouse, // Give priority to system messages (in particular keyboard, mouse,
// timer, and paint messages). // timer, and paint messages).
@ -125,12 +128,13 @@ int main(int argc, char **argv)
{ {
nsresult rv; nsresult rv;
nsIServiceManager* servMgr; nsIServiceManager* servMgr;
rv = NS_InitXPCOM(&servMgr, NULL, NULL); rv = NS_InitXPCOM(&servMgr);
NS_ASSERTION(NS_SUCCEEDED(rv), "NS_InitXPCOM failed"); NS_ASSERTION(NS_SUCCEEDED(rv), "NS_InitXPCOM failed");
nsViewerApp* app = new nsNativeViewerApp(); nsViewerApp* app = new nsNativeViewerApp();
NS_ADDREF(app); NS_ADDREF(app);
app->Initialize(argc, argv); app->Initialize(argc, argv);
int result = app->Run(); int result = app->Run();
app->Exit(); // this exit is needed for the -x case where the close box is never clicked
NS_RELEASE(app); NS_RELEASE(app);
rv = NS_ShutdownXPCOM(servMgr); rv = NS_ShutdownXPCOM(servMgr);
NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed"); NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed");