From 2b188ce191b5d6ca95ee48ccc757d25d152b256c Mon Sep 17 00:00:00 2001 From: "fur%netscape.com" Date: Tue, 16 Nov 1999 03:05:36 +0000 Subject: [PATCH] Fixed a problem with the NS_GENERIC_FACTORY_CONSTRUCTOR_INIT() macro. If the Init() routine happens to perform a balanced AddRef/Release, the instance will be prematurely destroyed when Release() is called. The change is to do the AddRef() before calling the initialization routine to stabilize the instance's ref-count. r: dp, putterman git-svn-id: svn://10.0.0.236/trunk@53608 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/xpcom/components/nsIGenericFactory.h | 10 ++++------ mozilla/xpcom/glue/nsIGenericFactory.h | 10 ++++------ 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/mozilla/xpcom/components/nsIGenericFactory.h b/mozilla/xpcom/components/nsIGenericFactory.h index 8aa8012cdfc..79e6bf370f2 100644 --- a/mozilla/xpcom/components/nsIGenericFactory.h +++ b/mozilla/xpcom/components/nsIGenericFactory.h @@ -156,14 +156,12 @@ _InstanceClass##Constructor(nsISupports *aOuter, REFNSIID aIID, void **aResult) if (NULL == inst) { \ rv = NS_ERROR_OUT_OF_MEMORY; \ return rv; \ - } \ - rv = inst->_InitMethod(); \ - if(NS_FAILED(rv)) { \ - NS_DELETEXPCOM(inst); \ - return rv; \ } \ NS_ADDREF(inst); \ - rv = inst->QueryInterface(aIID, aResult); \ + rv = inst->_InitMethod(); \ + if(NS_SUCCEEDED(rv)) { \ + rv = inst->QueryInterface(aIID, aResult); \ + } \ NS_RELEASE(inst); \ \ return rv; \ diff --git a/mozilla/xpcom/glue/nsIGenericFactory.h b/mozilla/xpcom/glue/nsIGenericFactory.h index 8aa8012cdfc..79e6bf370f2 100644 --- a/mozilla/xpcom/glue/nsIGenericFactory.h +++ b/mozilla/xpcom/glue/nsIGenericFactory.h @@ -156,14 +156,12 @@ _InstanceClass##Constructor(nsISupports *aOuter, REFNSIID aIID, void **aResult) if (NULL == inst) { \ rv = NS_ERROR_OUT_OF_MEMORY; \ return rv; \ - } \ - rv = inst->_InitMethod(); \ - if(NS_FAILED(rv)) { \ - NS_DELETEXPCOM(inst); \ - return rv; \ } \ NS_ADDREF(inst); \ - rv = inst->QueryInterface(aIID, aResult); \ + rv = inst->_InitMethod(); \ + if(NS_SUCCEEDED(rv)) { \ + rv = inst->QueryInterface(aIID, aResult); \ + } \ NS_RELEASE(inst); \ \ return rv; \