Bug 1028588 - Fix dangerous public destructors in xpcom/ - r=bsmedberg,khuey,nfroyd

This commit is contained in:
Benoit Jacob 2014-06-30 18:11:53 -04:00
parent c1e982f894
commit 35b82308d8
39 changed files with 174 additions and 63 deletions

View File

@ -396,6 +396,8 @@ NS_IMPL_ISUPPORTS(LowEventsReporter, nsIMemoryReporter)
*/
class nsJemallocFreeDirtyPagesRunnable MOZ_FINAL : public nsIRunnable
{
~nsJemallocFreeDirtyPagesRunnable() {}
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIRUNNABLE
@ -422,6 +424,8 @@ nsJemallocFreeDirtyPagesRunnable::Run()
*/
class nsMemoryPressureWatcher MOZ_FINAL : public nsIObserver
{
~nsMemoryPressureWatcher() {}
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER

View File

@ -114,6 +114,8 @@ IsAnonymous(const nsACString& aName)
class SystemReporter MOZ_FINAL : public nsIMemoryReporter
{
~SystemReporter() {}
public:
NS_DECL_THREADSAFE_ISUPPORTS

View File

@ -1273,9 +1273,11 @@ class nsCycleCollector : public nsIMemoryReporter
JSPurpleBuffer* mJSPurpleBuffer;
private:
virtual ~nsCycleCollector();
public:
nsCycleCollector();
virtual ~nsCycleCollector();
void RegisterJSRuntime(CycleCollectedJSRuntime* aJSRuntime);
void ForgetJSRuntime();
@ -1705,6 +1707,11 @@ NS_IMPL_ISUPPORTS(nsCycleCollectorLogSinkToFile, nsICycleCollectorLogSink)
class nsCycleCollectorLogger MOZ_FINAL : public nsICycleCollectorListener
{
~nsCycleCollectorLogger()
{
ClearDescribers();
}
public:
nsCycleCollectorLogger()
: mLogSink(nsCycleCollector_createLogSink())
@ -1715,11 +1722,6 @@ public:
{
}
~nsCycleCollectorLogger()
{
ClearDescribers();
}
NS_DECL_ISUPPORTS
void SetAllTraces()
@ -2509,6 +2511,13 @@ private:
// removed.
class JSPurpleBuffer
{
~JSPurpleBuffer()
{
MOZ_ASSERT(mValues.IsEmpty());
MOZ_ASSERT(mObjects.IsEmpty());
MOZ_ASSERT(mTenuredObjects.IsEmpty());
}
public:
JSPurpleBuffer(JSPurpleBuffer*& aReferenceToThis)
: mReferenceToThis(aReferenceToThis)
@ -2518,13 +2527,6 @@ public:
mozilla::HoldJSObjects(this);
}
~JSPurpleBuffer()
{
MOZ_ASSERT(mValues.IsEmpty());
MOZ_ASSERT(mObjects.IsEmpty());
MOZ_ASSERT(mTenuredObjects.IsEmpty());
}
void Destroy()
{
mReferenceToThis = nullptr;

View File

@ -40,6 +40,12 @@ protected:
MessageLoopForIO::FileDescriptorWatcher mReadWatcher;
int mFd;
virtual ~FdWatcher()
{
// StopWatching should have run.
MOZ_ASSERT(mFd == -1);
}
public:
FdWatcher()
: mFd(-1)
@ -47,12 +53,6 @@ public:
MOZ_ASSERT(NS_IsMainThread());
}
virtual ~FdWatcher()
{
// StopWatching should have run.
MOZ_ASSERT(mFd == -1);
}
/**
* Open the fd to watch. If we encounter an error, return -1.
*/

View File

@ -15,9 +15,10 @@
*/
class nsGZFileWriter : public nsIGZFileWriter
{
virtual ~nsGZFileWriter();
public:
nsGZFileWriter();
virtual ~nsGZFileWriter();
NS_DECL_ISUPPORTS
NS_DECL_NSIGZFILEWRITER

View File

@ -66,6 +66,7 @@ interface nsIStatusReporterManager : nsISupports
*/
#define NS_STATUS_REPORTER_IMPLEMENT(_classname, _name, _desc_Function) \
class StatusReporter_##_classname MOZ_FINAL : public nsIStatusReporter { \
~StatusReporter_##_classname() {} \
public: \
NS_DECL_ISUPPORTS \
NS_IMETHOD GetName(nsACString &name) \

View File

@ -29,9 +29,10 @@ public:
mConsumerTarget = NS_GetCurrentThread();
}
}
~nsInterfaceRequestorAgg();
private:
~nsInterfaceRequestorAgg();
nsCOMPtr<nsIInterfaceRequestor> mFirst, mSecond;
nsCOMPtr<nsIEventTarget> mConsumerTarget;
};

View File

@ -496,6 +496,8 @@ public:
}
private:
~DumpReportCallback() {}
bool mIsFirst;
nsRefPtr<nsGZFileWriter> mWriter;
};
@ -588,6 +590,8 @@ public:
NS_IMETHOD Callback(nsISupports* aData);
private:
~TempDirMemoryFinishCallback() {}
nsRefPtr<nsGZFileWriter> mrWriter;
nsCOMPtr<nsIFile> mrTmpFile;
nsCString mrFilename;
@ -823,6 +827,8 @@ public:
}
private:
~FinishReportingCallback() {}
nsCOMPtr<nsIFinishDumpingCallback> mFinishDumping;
nsCOMPtr<nsISupports> mFinishDumpingData;
};

View File

@ -20,14 +20,14 @@ class nsACString;
*/
class nsMemoryInfoDumper : public nsIMemoryInfoDumper
{
virtual ~nsMemoryInfoDumper();
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIMEMORYINFODUMPER
nsMemoryInfoDumper();
virtual ~nsMemoryInfoDumper();
public:
static void Initialize();
#ifdef MOZ_DMD

View File

@ -118,6 +118,8 @@ ResidentUniqueDistinguishedAmount(int64_t* aN)
class ResidentUniqueReporter MOZ_FINAL : public nsIMemoryReporter
{
~ResidentUniqueReporter() {}
public:
NS_DECL_ISUPPORTS
@ -558,6 +560,8 @@ NS_IMPL_ISUPPORTS(PrivateReporter, nsIMemoryReporter)
#ifdef HAVE_VSIZE_AND_RESIDENT_REPORTERS
class VsizeReporter MOZ_FINAL : public nsIMemoryReporter
{
~VsizeReporter() {}
public:
NS_DECL_ISUPPORTS
@ -583,6 +587,8 @@ NS_IMPL_ISUPPORTS(VsizeReporter, nsIMemoryReporter)
class ResidentReporter MOZ_FINAL : public nsIMemoryReporter
{
~ResidentReporter() {}
public:
NS_DECL_ISUPPORTS
@ -615,6 +621,8 @@ NS_IMPL_ISUPPORTS(ResidentReporter, nsIMemoryReporter)
class PageFaultsSoftReporter MOZ_FINAL : public nsIMemoryReporter
{
~PageFaultsSoftReporter() {}
public:
NS_DECL_ISUPPORTS
@ -657,6 +665,8 @@ PageFaultsHardDistinguishedAmount(int64_t* aAmount)
class PageFaultsHardReporter MOZ_FINAL : public nsIMemoryReporter
{
~PageFaultsHardReporter() {}
public:
NS_DECL_ISUPPORTS
@ -704,6 +714,8 @@ HeapOverheadRatio(jemalloc_stats_t* aStats)
class JemallocHeapReporter MOZ_FINAL : public nsIMemoryReporter
{
~JemallocHeapReporter() {}
public:
NS_DECL_ISUPPORTS
@ -808,6 +820,8 @@ class AtomTablesReporter MOZ_FINAL : public nsIMemoryReporter
{
MOZ_DEFINE_MALLOC_SIZE_OF(MallocSizeOf)
~AtomTablesReporter() {}
public:
NS_DECL_ISUPPORTS
@ -1443,6 +1457,8 @@ nsMemoryReporterManager::UnblockRegistrationAndRestoreOriginalReporters()
// passed to nsIMemoryReporter::CollectReports.
class Int64Wrapper MOZ_FINAL : public nsISupports
{
~Int64Wrapper() {}
public:
NS_DECL_ISUPPORTS
Int64Wrapper() : mValue(0)
@ -1455,6 +1471,8 @@ NS_IMPL_ISUPPORTS0(Int64Wrapper)
class ExplicitCallback MOZ_FINAL : public nsIHandleReportCallback
{
~ExplicitCallback() {}
public:
NS_DECL_ISUPPORTS

View File

@ -24,12 +24,13 @@ class MemoryReport;
class nsMemoryReporterManager : public nsIMemoryReporterManager
{
virtual ~nsMemoryReporterManager();
public:
NS_DECL_THREADSAFE_ISUPPORTS
NS_DECL_NSIMEMORYREPORTERMANAGER
nsMemoryReporterManager();
virtual ~nsMemoryReporterManager();
// Gets the memory reporter manager service.
static nsMemoryReporterManager* GetOrCreate()

View File

@ -34,9 +34,6 @@ class MessageLoopIdleTask
public:
MOZ_DECLARE_REFCOUNTED_TYPENAME(MessageLoopIdleTask)
MessageLoopIdleTask(nsIRunnable* aTask, uint32_t aEnsureRunsAfterMS);
virtual ~MessageLoopIdleTask()
{
}
virtual void Run();
private:
@ -44,6 +41,8 @@ private:
nsCOMPtr<nsIRunnable> mTask;
nsCOMPtr<nsITimer> mTimer;
virtual ~MessageLoopIdleTask() {}
};
/**
@ -61,13 +60,14 @@ class MessageLoopTimerCallback
{
public:
MessageLoopTimerCallback(MessageLoopIdleTask* aTask);
virtual ~MessageLoopTimerCallback() {};
NS_DECL_ISUPPORTS
NS_DECL_NSITIMERCALLBACK
private:
WeakPtr<MessageLoopIdleTask> mTask;
virtual ~MessageLoopTimerCallback() {}
};
MessageLoopIdleTask::MessageLoopIdleTask(nsIRunnable* aTask,

View File

@ -15,6 +15,7 @@ class nsMessageLoop : public nsIMessageLoop
NS_DECL_ISUPPORTS
NS_DECL_NSIMESSAGELOOP
private:
virtual ~nsMessageLoop()
{
}

View File

@ -17,12 +17,12 @@ public:
nsStatusReporter(nsACString& aProcess, nsACString& aDesc);
virtual ~nsStatusReporter();
protected:
private:
nsCString sProcess;
nsCString sName;
nsCString sDesc;
virtual ~nsStatusReporter();
};
@ -33,8 +33,9 @@ public:
NS_DECL_NSISTATUSREPORTERMANAGER
nsStatusReporterManager();
virtual ~nsStatusReporterManager();
private:
nsCOMArray<nsIStatusReporter> mReporters;
virtual ~nsStatusReporterManager();
};

View File

@ -10,6 +10,8 @@
class nsVersionComparatorImpl MOZ_FINAL : public nsIVersionComparator
{
~nsVersionComparatorImpl() {}
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIVERSIONCOMPARATOR

View File

@ -380,6 +380,8 @@ private:
"explicit/icu", KIND_HEAP, UNITS_BYTES, MemoryAllocated(),
"Memory used by ICU, a Unicode and globalization support library.");
}
~ICUReporter() {}
};
NS_IMPL_ISUPPORTS(ICUReporter, nsIMemoryReporter)
@ -401,6 +403,8 @@ private:
"explicit/media/libogg", KIND_HEAP, UNITS_BYTES, MemoryAllocated(),
"Memory allocated through libogg for Ogg, Theora, and related media files.");
}
~OggReporter() {}
};
NS_IMPL_ISUPPORTS(OggReporter, nsIMemoryReporter)
@ -423,6 +427,8 @@ private:
"explicit/media/libvpx", KIND_HEAP, UNITS_BYTES, MemoryAllocated(),
"Memory allocated through libvpx for WebM media files.");
}
~VPXReporter() {}
};
NS_IMPL_ISUPPORTS(VPXReporter, nsIMemoryReporter)
@ -446,6 +452,8 @@ private:
"explicit/media/libnestegg", KIND_HEAP, UNITS_BYTES, MemoryAllocated(),
"Memory allocated through libnestegg for WebM media files.");
}
~NesteggReporter() {}
};
NS_IMPL_ISUPPORTS(NesteggReporter, nsIMemoryReporter)

View File

@ -104,6 +104,8 @@ namespace mozilla {
class GenericModule MOZ_FINAL : public nsIModule
{
~GenericModule() {}
public:
GenericModule(const mozilla::Module* aData)
: mData(aData)

View File

@ -13,6 +13,16 @@
#include "mozilla/Module.h"
#include "prlink.h"
class nsNativeModuleLoader;
namespace mozilla {
template<>
struct HasDangerousPublicDestructor<nsNativeModuleLoader>
{
static const bool value = true;
};
}
class nsNativeModuleLoader : public mozilla::ModuleLoader
{
public:

View File

@ -64,6 +64,8 @@ private:
: nsArrayBase(aBaseArray)
{
}
~nsArray() {}
};
class nsArrayCC MOZ_FINAL : public nsArrayBase
@ -84,6 +86,8 @@ private:
: nsArrayBase(aBaseArray)
{
}
~nsArrayCC() {}
};
#endif

View File

@ -93,7 +93,10 @@ nsHashPropertyBag::DeleteProperty(const nsAString& name)
// nsSimpleProperty class and impl; used for GetEnumerator
//
class nsSimpleProperty MOZ_FINAL : public nsIProperty {
class nsSimpleProperty MOZ_FINAL : public nsIProperty
{
~nsSimpleProperty() {}
public:
nsSimpleProperty(const nsAString& aName, nsIVariant* aValue)
: mName(aName), mValue(aValue)

View File

@ -16,7 +16,6 @@ class nsHashPropertyBag : public nsIWritablePropertyBag
{
public:
nsHashPropertyBag() { }
virtual ~nsHashPropertyBag() {}
NS_DECL_THREADSAFE_ISUPPORTS
@ -31,6 +30,8 @@ public:
protected:
// a hash table of string -> nsIVariant
nsInterfaceHashtable<nsStringHashKey, nsIVariant> mPropertyHash;
virtual ~nsHashPropertyBag() {}
};
// Note: NS_NewHashPropertyBag returns a HPB that

View File

@ -12,6 +12,8 @@
class nsINIParserImpl MOZ_FINAL :
public nsIINIParser
{
~nsINIParserImpl() {}
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIINIPARSER

View File

@ -20,6 +20,8 @@ class nsINIParserFactory MOZ_FINAL :
public nsIINIParserFactory,
public nsIFactory
{
~nsINIParserFactory() {}
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIINIPARSERFACTORY

View File

@ -13,11 +13,12 @@
static const uint32_t kAutoArraySize = 8;
class nsSupportsArray MOZ_FINAL : public nsISupportsArray {
public:
nsSupportsArray(void);
class nsSupportsArray MOZ_FINAL : public nsISupportsArray
{
~nsSupportsArray(void); // nonvirtual since we're not subclassed
public:
nsSupportsArray(void);
static nsresult
Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);

View File

@ -20,6 +20,8 @@ namespace mozilla {
*/
class GenericFactory MOZ_FINAL : public nsIFactory
{
~GenericFactory() {}
public:
typedef Module::ConstructorProcPtr ConstructorProcPtr;

View File

@ -24,9 +24,10 @@
class NS_COM_GLUE nsCategoryObserver MOZ_FINAL : public nsIObserver
{
~nsCategoryObserver();
public:
nsCategoryObserver(const char* aCategory);
~nsCategoryObserver();
void ListenerDied();
nsInterfaceHashtable<nsCStringHashKey, nsISupports>& GetHash()

View File

@ -290,6 +290,8 @@ namespace {
class nsNameThreadRunnable MOZ_FINAL : public nsIRunnable
{
~nsNameThreadRunnable() {}
public:
nsNameThreadRunnable(const nsACString& aName) : mName(aName) {}

View File

@ -451,17 +451,16 @@ public:
return *aResult ? NS_OK : NS_ERROR_FAILURE;
}
// Virtual destructor since subclass nsPathsDirectoryEnumerator
// does not re-implement Release()
virtual ~nsAppDirectoryEnumerator()
{
}
protected:
nsIDirectoryServiceProvider* mProvider;
const char** mCurrentKey;
nsCOMPtr<nsIFile> mNext;
// Virtual destructor since subclass nsPathsDirectoryEnumerator
// does not re-implement Release()
virtual ~nsAppDirectoryEnumerator()
{
}
};
NS_IMPL_ISUPPORTS(nsAppDirectoryEnumerator, nsISimpleEnumerator)
@ -475,8 +474,11 @@ NS_IMPL_ISUPPORTS(nsAppDirectoryEnumerator, nsISimpleEnumerator)
#define PATH_SEPARATOR ':'
#endif
class nsPathsDirectoryEnumerator : public nsAppDirectoryEnumerator
class nsPathsDirectoryEnumerator MOZ_FINAL
: public nsAppDirectoryEnumerator
{
~nsPathsDirectoryEnumerator() {}
public:
/**
* aKeyList is a null-terminated list.

View File

@ -31,10 +31,6 @@ public:
nsBinaryOutputStream()
{
}
// virtual dtor since subclasses call our Release()
virtual ~nsBinaryOutputStream()
{
}
protected:
// nsISupports methods
@ -54,6 +50,12 @@ protected:
nsCOMPtr<nsIOutputStream> mOutputStream;
nsCOMPtr<nsIStreamBufferAccess> mBufferAccess;
private:
// virtual dtor since subclasses call our Release()
virtual ~nsBinaryOutputStream()
{
}
};
#define NS_BINARYINPUTSTREAM_CID \
@ -74,10 +76,6 @@ public:
nsBinaryInputStream()
{
}
// virtual dtor since subclasses call our Release()
virtual ~nsBinaryInputStream()
{
}
protected:
// nsISupports methods
@ -94,6 +92,12 @@ protected:
nsCOMPtr<nsIInputStream> mInputStream;
nsCOMPtr<nsIStreamBufferAccess> mBufferAccess;
private:
// virtual dtor since subclasses call our Release()
virtual ~nsBinaryInputStream()
{
}
};
#endif // nsBinaryStream_h___

View File

@ -37,7 +37,6 @@ public:
NS_DECL_NSIDIRECTORYSERVICEPROVIDER2
nsDirectoryService();
~nsDirectoryService();
static void RealInit();
void RegisterCategoryProviders();
@ -48,6 +47,8 @@ public:
static nsDirectoryService* gService;
private:
~nsDirectoryService();
nsresult GetCurrentProcessDirectory(nsIFile** aFile);
nsInterfaceHashtable<nsCStringHashKey, nsIFile> mHashtable;

View File

@ -17,6 +17,8 @@
class nsIOUtil MOZ_FINAL : public nsIIOUtil
{
~nsIOUtil() {}
public:
NS_DECL_THREADSAFE_ISUPPORTS
NS_DECL_NSIIOUTIL

View File

@ -233,11 +233,6 @@ public:
{
}
// virtual since subclasses call superclass Release()
virtual ~nsAStreamCopier()
{
}
// kick off the async copy...
nsresult Start(nsIInputStream* aSource,
nsIOutputStream* aSink,
@ -475,6 +470,11 @@ protected:
bool mCloseSink;
bool mCanceled;
nsresult mCancelStatus;
// virtual since subclasses call superclass Release()
virtual ~nsAStreamCopier()
{
}
};
NS_IMPL_ISUPPORTS(nsAStreamCopier,

View File

@ -40,6 +40,8 @@ private:
const char* aName,
const mozilla::dom::NativePropertyHooks* aNativePropHooks);
~ShimInterfaceInfo() {}
private:
nsIID mIID;
nsAutoCString mName;

View File

@ -25,10 +25,11 @@ public:
NS_DEFINE_STATIC_IID_ACCESSOR(IFoo, NS_IFOO_IID)
class Foo MOZ_FINAL : public IFoo {
~Foo();
public:
Foo(int32_t aID);
~Foo();
// nsISupports implementation
NS_DECL_ISUPPORTS
@ -78,7 +79,6 @@ class Bar MOZ_FINAL : public IBar {
public:
explicit Bar(nsCOMArray<IBar>& aArray);
~Bar();
// nsISupports implementation
NS_DECL_ISUPPORTS
@ -86,6 +86,8 @@ public:
static int32_t sReleaseCalled;
private:
~Bar();
nsCOMArray<IBar>& mArray;
};

View File

@ -36,6 +36,7 @@ NS_DEFINE_STATIC_IID_ACCESSOR(nsITestService, NS_ITESTSERVICE_IID)
class nsTestService MOZ_FINAL : public nsITestService,
public nsSupportsWeakReference
{
~nsTestService() {}
public:
NS_DECL_ISUPPORTS
};

View File

@ -87,6 +87,8 @@ private:
class Factory MOZ_FINAL : public nsIFactory
{
~Factory() {}
public:
NS_DECL_THREADSAFE_ISUPPORTS
@ -107,6 +109,8 @@ NS_IMPL_ISUPPORTS(Factory, nsIFactory)
class Component1 MOZ_FINAL : public nsISupports
{
~Component1() {}
public:
NS_DECL_THREADSAFE_ISUPPORTS
@ -126,6 +130,8 @@ NS_INTERFACE_MAP_END
class Component2 MOZ_FINAL : public nsISupports
{
~Component2() {}
public:
NS_DECL_THREADSAFE_ISUPPORTS

View File

@ -47,6 +47,8 @@ static bool gAllThreadsShutDown = false;
class Listener MOZ_FINAL : public nsIThreadPoolListener
{
~Listener() {}
public:
NS_DECL_THREADSAFE_ISUPPORTS
NS_DECL_NSITHREADPOOLLISTENER

View File

@ -34,6 +34,14 @@ class nsFoo : public nsISupports {
virtual ~nsFoo() {}
};
namespace mozilla {
template<>
struct HasDangerousPublicDestructor<nsFoo>
{
static const bool value = true;
};
}
NS_IMPL_ISUPPORTS0(nsFoo)
class TestSuicide : public nsRunnable {
@ -55,8 +63,9 @@ private:
};
class nsBar : public nsISupports {
NS_DECL_ISUPPORTS
virtual ~nsBar() {}
public:
NS_DECL_ISUPPORTS
void DoBar1(void) {
gRunnableExecuted[TEST_CALL_VOID_ARG_VOID_RETURN] = true;
}

View File

@ -92,6 +92,8 @@ public:
return NS_OK;
}
private:
~TimerCallback() {}
nsIThread** mThreadPtr;
ReentrantMonitor* mReentrantMonitor;
};