Skip to content

Commit

Permalink
Bug #388532 --> nsMoarkFactoryFactory leaks the global mork mdb facto…
Browse files Browse the repository at this point in the history
…ry. Change it to a service, and use a com ptr to keep track of the mdb factory.

sr=bienvenu
r=standard8
r=sspitzer for toolkit changes
  • Loading branch information
smacgregor committed Jul 25, 2007
1 parent 068fab6 commit 3124089
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 53 deletions.
12 changes: 6 additions & 6 deletions db/mork/build/nsIMdbFactoryFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,19 @@

class nsIMdbFactory;

// d5440650-2807-11d3-8d75-00805f8a6617
// 2794D0B7-E740-47a4-91C0-3E4FCB95B806
#define NS_IMDBFACTORYFACTORY_IID \
{ 0xd5440650, 0x2807, 0x11d3, { 0x8d, 0x75, 0x00, 0x80, 0x5f, 0x8a, 0x66, 0x17}}
{ 0x2794d0b7, 0xe740, 0x47a4, { 0x91, 0xc0, 0x3e, 0x4f, 0xcb, 0x95, 0xb8, 0x6 } }

// because Mork doesn't support XPCOM, we have to wrap the mdb factory interface
// with an interface that gives you an mdb factory.
class nsIMdbFactoryFactory : public nsISupports
class nsIMdbFactoryService : public nsISupports
{
public:
NS_DECLARE_STATIC_IID_ACCESSOR(NS_IMDBFACTORYFACTORY_IID)
NS_IMETHOD GetMdbFactory(nsIMdbFactory **aFactory) = 0;
NS_DECLARE_STATIC_IID_ACCESSOR(NS_IMDBFACTORYFACTORY_IID)
NS_IMETHOD GetMdbFactory(nsIMdbFactory **aFactory) = 0;
};

NS_DEFINE_STATIC_IID_ACCESSOR(nsIMdbFactoryFactory, NS_IMDBFACTORYFACTORY_IID)
NS_DEFINE_STATIC_IID_ACCESSOR(nsIMdbFactoryService, NS_IMDBFACTORYFACTORY_IID)

#endif
54 changes: 13 additions & 41 deletions db/mork/build/nsMorkFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,66 +44,38 @@
#include "nsIMdbFactoryFactory.h"
#include "mdb.h"

class nsMorkFactoryFactory : public nsIMdbFactoryFactory
class nsMorkFactoryService : public nsIMdbFactoryService
{
public:
nsMorkFactoryFactory();
nsMorkFactoryService() {};
// nsISupports methods
NS_DECL_ISUPPORTS

NS_IMETHOD GetMdbFactory(nsIMdbFactory **aFactory);

protected:
nsCOMPtr<nsIMdbFactory> mMdbFactory;
};

NS_GENERIC_FACTORY_CONSTRUCTOR(nsMorkFactoryFactory)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsMorkFactoryService)

static const nsModuleComponentInfo components[] =
{
{ "Mork Factory",
{ "Mork Factory Service",
NS_MORK_CID,
NS_MORK_CONTRACTID,
nsMorkFactoryFactoryConstructor
nsMorkFactoryServiceConstructor
}
};

NS_IMPL_NSGETMODULE(nsMorkModule, components)

NS_IMPL_ISUPPORTS1(nsMorkFactoryService, nsIMdbFactoryService)



static nsIMdbFactory *gMDBFactory = nsnull;

NS_IMPL_ADDREF(nsMorkFactoryFactory)
NS_IMPL_RELEASE(nsMorkFactoryFactory)

NS_IMETHODIMP
nsMorkFactoryFactory::QueryInterface(REFNSIID iid, void** result)
NS_IMETHODIMP nsMorkFactoryService::GetMdbFactory(nsIMdbFactory **aFactory)
{
if (! result)
return NS_ERROR_NULL_POINTER;

*result = nsnull;
if(iid.Equals(NS_GET_IID(nsIMdbFactoryFactory)) ||
iid.Equals(NS_GET_IID(nsISupports))) {
*result = static_cast<nsIMdbFactoryFactory*>(this);
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
if (!mMdbFactory)
mMdbFactory = MakeMdbFactory();
NS_IF_ADDREF(*aFactory = mMdbFactory);
return *aFactory ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}



nsMorkFactoryFactory::nsMorkFactoryFactory()
{
}

NS_IMETHODIMP nsMorkFactoryFactory::GetMdbFactory(nsIMdbFactory **aFactory)
{
if (!gMDBFactory)
gMDBFactory = MakeMdbFactory();
*aFactory = gMDBFactory;
NS_IF_ADDREF(gMDBFactory);
return (gMDBFactory) ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}

4 changes: 1 addition & 3 deletions toolkit/components/history/src/nsGlobalHistory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2640,9 +2640,7 @@ nsGlobalHistory::OpenDB()
nsCOMPtr <nsIFile> historyFile;
rv = NS_GetSpecialDirectory(NS_APP_HISTORY_50_FILE, getter_AddRefs(historyFile));
NS_ENSURE_SUCCESS(rv, rv);

nsCOMPtr<nsIMdbFactoryFactory> factoryfactory =
do_CreateInstance(NS_MORK_CONTRACTID, &rv);
nsCOMPtr <nsIMdbFactoryService> factoryfactory = do_GetService(NS_MORK_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);

rv = factoryfactory->GetMdbFactory(&gMdbFactory);
Expand Down
2 changes: 1 addition & 1 deletion toolkit/components/satchel/src/nsFormHistory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ nsFormHistory::OpenDatabase()
historyFile->Append(NS_ConvertUTF8toUTF16(kFormHistoryFileName));

// Get an Mdb Factory
nsCOMPtr<nsIMdbFactoryFactory> mdbFactory = do_CreateInstance(NS_MORK_CONTRACTID, &rv);
nsCOMPtr <nsIMdbFactoryService> mdbFactory = do_GetService(NS_MORK_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
rv = mdbFactory->GetMdbFactory(getter_AddRefs(mMdbFactory));
NS_ENSURE_SUCCESS(rv, rv);
Expand Down
3 changes: 1 addition & 2 deletions xpfe/components/history/src/nsGlobalHistory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2588,8 +2588,7 @@ nsGlobalHistory::OpenDB()
rv = NS_GetSpecialDirectory(NS_APP_HISTORY_50_FILE, getter_AddRefs(historyFile));
NS_ENSURE_SUCCESS(rv, rv);

nsCOMPtr<nsIMdbFactoryFactory> factoryfactory =
do_CreateInstance(NS_MORK_CONTRACTID, &rv);
nsCOMPtr <nsIMdbFactoryService> factoryfactory = do_GetService(NS_MORK_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);

rv = factoryfactory->GetMdbFactory(&gMdbFactory);
Expand Down

0 comments on commit 3124089

Please sign in to comment.