From 54edd67d97bf7f1e9be26ef2c058edd770686efa Mon Sep 17 00:00:00 2001 From: "mcafee%netscape.com" Date: Fri, 30 Apr 1999 22:20:24 +0000 Subject: [PATCH] Switching to NS_WITH_SERIVICE() to properly release services (5403). a=chofmann, r=warren@netscap.com git-svn-id: svn://10.0.0.236/trunk@29896 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/widget/src/gtk/nsAppShell.cpp | 17 +++++++++-------- mozilla/widget/src/gtk/nsClipboard.cpp | 19 +++++++------------ mozilla/widget/src/gtk/nsDragService.cpp | 9 ++++----- 3 files changed, 20 insertions(+), 25 deletions(-) diff --git a/mozilla/widget/src/gtk/nsAppShell.cpp b/mozilla/widget/src/gtk/nsAppShell.cpp index 88f554ccf65..504eeff4ad6 100644 --- a/mozilla/widget/src/gtk/nsAppShell.cpp +++ b/mozilla/widget/src/gtk/nsAppShell.cpp @@ -104,11 +104,15 @@ NS_METHOD nsAppShell::Create(int *argc, char **argv) nsICmdLineService *cmdLineArgs=nsnull; nsresult rv = NS_OK; - rv = nsServiceManager::GetService(kCmdLineServiceCID, - kICmdLineServiceIID, - (nsISupports **)&cmdLineArgs); + NS_WITH_SERVICE(nsICmdLineService, cmdLineArgs, kCmdLineServiceCID, &rv); + if (NS_FAILED(rv)) return rv; + rv = cmdLineArgs->GetArgc(argc); + if(NS_FAILED(rv)) return rv; + rv = cmdLineArgs->GetArgv(&argv); + if(NS_FAILED(rv)) return rv; + #endif gtk_set_locale (); @@ -161,11 +165,8 @@ NS_METHOD nsAppShell::Run() PLEventQueue * EQueue = nsnull; // Get the event queue service - rv = nsServiceManager::GetService(kEventQueueServiceCID, - kIEventQueueServiceIID, - (nsISupports **) &mEventQService); - - if (NS_OK != rv) { + NS_WITH_SERVICE(nsIEventQueueService, mEventQService, kEventQueueServiceCID, &rv); + if (NS_FAILED(rv)) { NS_ASSERTION("Could not obtain event queue service", PR_FALSE); return rv; } diff --git a/mozilla/widget/src/gtk/nsClipboard.cpp b/mozilla/widget/src/gtk/nsClipboard.cpp index 8f4f6eb33e8..a186c29e8a7 100644 --- a/mozilla/widget/src/gtk/nsClipboard.cpp +++ b/mozilla/widget/src/gtk/nsClipboard.cpp @@ -170,10 +170,9 @@ void nsClipboard::SetTopLevelWidget(GtkWidget* w) sWidget = w; // Get the clipboard from the service manager. - nsIClipboard* clipboard; - nsresult rv = nsServiceManager::GetService(kCClipboardCID, - kIClipboardIID, - (nsISupports **)&clipboard); + nsresult rv; + NS_WITH_SERVICE(nsIClipboard, clipboard, kCClipboardCID, &rv); + if (!NS_SUCCEEDED(rv)) { printf("Couldn't get clipboard service!\n"); return; @@ -214,9 +213,6 @@ void nsClipboard::SetTopLevelWidget(GtkWidget* w) GDK_SELECTION_PRIMARY, GDK_SELECTION_TYPE_STRING, GDK_SELECTION_TYPE_STRING); - - // We're done with our reference to the clipboard. - NS_IF_RELEASE(clipboard); } @@ -417,11 +413,10 @@ nsClipboard::SelectionReceivedCB (GtkWidget *aWidget, // ARGHH! GTK doesn't pass the arg to the callback, so we can't // get "this" back! Until we solve this, get it from the service mgr: - nsIClipboard* iclipboard; - nsresult rv = nsServiceManager::GetService(kCClipboardCID, - kIClipboardIID, - (nsISupports **)&iclipboard); - if (!NS_SUCCEEDED(rv)) { + nsresult rv; + NS_WITH_SERVICE(nsIClipboard, iclipboard, kCClipboardCID, &rv); + + if (NS_FAILED(rv)) { printf("Couldn't get clipboard service!\n"); return; } diff --git a/mozilla/widget/src/gtk/nsDragService.cpp b/mozilla/widget/src/gtk/nsDragService.cpp index afd963161d0..0391c535fcf 100644 --- a/mozilla/widget/src/gtk/nsDragService.cpp +++ b/mozilla/widget/src/gtk/nsDragService.cpp @@ -105,11 +105,10 @@ void nsDragService::SetTopLevelWidget(GtkWidget* w) sWidget = w; // Get the DragService from the service manager. - nsIDragService* dragService; - nsresult rv = nsServiceManager::GetService(kCDragServiceCID, - kIDragServiceIID, - (nsISupports**)&dragService); - if (!NS_SUCCEEDED(rv)) { + nsresult rv; + NS_WITH_SERVICE(nsIDragService, dragService, kCDragServiceCID, &rv); + + if (NS_FAILED(rv)) { return; }