Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Bug 1028588 - Fix dangerous public destructors in xpcom/ - r=bsmedber…
…g,khuey,nfroyd
  • Loading branch information
Benoit Jacob committed Jun 30, 2014
1 parent d227511 commit 81effa4
Show file tree
Hide file tree
Showing 39 changed files with 173 additions and 62 deletions.
4 changes: 4 additions & 0 deletions xpcom/base/AvailableMemoryTracker.cpp
Expand Up @@ -396,6 +396,8 @@ NS_IMPL_ISUPPORTS(LowEventsReporter, nsIMemoryReporter)
*/
class nsJemallocFreeDirtyPagesRunnable MOZ_FINAL : public nsIRunnable
{
~nsJemallocFreeDirtyPagesRunnable() {}

public:
NS_DECL_ISUPPORTS
NS_DECL_NSIRUNNABLE
Expand All @@ -422,6 +424,8 @@ nsJemallocFreeDirtyPagesRunnable::Run()
*/
class nsMemoryPressureWatcher MOZ_FINAL : public nsIObserver
{
~nsMemoryPressureWatcher() {}

public:
NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER
Expand Down
2 changes: 2 additions & 0 deletions xpcom/base/SystemMemoryReporter.cpp
Expand Up @@ -114,6 +114,8 @@ IsAnonymous(const nsACString& aName)

class SystemReporter MOZ_FINAL : public nsIMemoryReporter
{
~SystemReporter() {}

public:
NS_DECL_THREADSAFE_ISUPPORTS

Expand Down
28 changes: 15 additions & 13 deletions xpcom/base/nsCycleCollector.cpp
Expand Up @@ -1279,9 +1279,11 @@ class nsCycleCollector : public nsIMemoryReporter

JSPurpleBuffer* mJSPurpleBuffer;

private:
virtual ~nsCycleCollector();

public:
nsCycleCollector();
virtual ~nsCycleCollector();

void RegisterJSRuntime(CycleCollectedJSRuntime* aJSRuntime);
void ForgetJSRuntime();
Expand Down Expand Up @@ -1711,6 +1713,11 @@ NS_IMPL_ISUPPORTS(nsCycleCollectorLogSinkToFile, nsICycleCollectorLogSink)

class nsCycleCollectorLogger MOZ_FINAL : public nsICycleCollectorListener
{
~nsCycleCollectorLogger()
{
ClearDescribers();
}

public:
nsCycleCollectorLogger()
: mLogSink(nsCycleCollector_createLogSink())
Expand All @@ -1721,11 +1728,6 @@ class nsCycleCollectorLogger MOZ_FINAL : public nsICycleCollectorListener
{
}

~nsCycleCollectorLogger()
{
ClearDescribers();
}

NS_DECL_ISUPPORTS

void SetAllTraces()
Expand Down Expand Up @@ -2515,6 +2517,13 @@ class SegmentedArray
// removed.
class JSPurpleBuffer
{
~JSPurpleBuffer()
{
MOZ_ASSERT(mValues.IsEmpty());
MOZ_ASSERT(mObjects.IsEmpty());
MOZ_ASSERT(mTenuredObjects.IsEmpty());
}

public:
JSPurpleBuffer(JSPurpleBuffer*& aReferenceToThis)
: mReferenceToThis(aReferenceToThis)
Expand All @@ -2524,13 +2533,6 @@ class JSPurpleBuffer
mozilla::HoldJSObjects(this);
}

~JSPurpleBuffer()
{
MOZ_ASSERT(mValues.IsEmpty());
MOZ_ASSERT(mObjects.IsEmpty());
MOZ_ASSERT(mTenuredObjects.IsEmpty());
}

void Destroy()
{
mReferenceToThis = nullptr;
Expand Down
12 changes: 6 additions & 6 deletions xpcom/base/nsDumpUtils.h
Expand Up @@ -40,19 +40,19 @@ class FdWatcher
MessageLoopForIO::FileDescriptorWatcher mReadWatcher;
int mFd;

virtual ~FdWatcher()
{
// StopWatching should have run.
MOZ_ASSERT(mFd == -1);
}

public:
FdWatcher()
: mFd(-1)
{
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.
*/
Expand Down
3 changes: 2 additions & 1 deletion xpcom/base/nsGZFileWriter.h
Expand Up @@ -15,9 +15,10 @@
*/
class nsGZFileWriter : public nsIGZFileWriter
{
virtual ~nsGZFileWriter();

public:
nsGZFileWriter();
virtual ~nsGZFileWriter();

NS_DECL_ISUPPORTS
NS_DECL_NSIGZFILEWRITER
Expand Down
1 change: 1 addition & 0 deletions xpcom/base/nsIStatusReporter.idl
Expand Up @@ -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) \
Expand Down
3 changes: 2 additions & 1 deletion xpcom/base/nsInterfaceRequestorAgg.cpp
Expand Up @@ -29,9 +29,10 @@ class nsInterfaceRequestorAgg MOZ_FINAL : public nsIInterfaceRequestor
mConsumerTarget = NS_GetCurrentThread();
}
}
~nsInterfaceRequestorAgg();

private:
~nsInterfaceRequestorAgg();

nsCOMPtr<nsIInterfaceRequestor> mFirst, mSecond;
nsCOMPtr<nsIEventTarget> mConsumerTarget;
};
Expand Down
6 changes: 6 additions & 0 deletions xpcom/base/nsMemoryInfoDumper.cpp
Expand Up @@ -496,6 +496,8 @@ class DumpReportCallback MOZ_FINAL : public nsIHandleReportCallback
}

private:
~DumpReportCallback() {}

bool mIsFirst;
nsRefPtr<nsGZFileWriter> mWriter;
};
Expand Down Expand Up @@ -588,6 +590,8 @@ class TempDirMemoryFinishCallback MOZ_FINAL : public nsIFinishReportingCallback
NS_IMETHOD Callback(nsISupports* aData);

private:
~TempDirMemoryFinishCallback() {}

nsRefPtr<nsGZFileWriter> mrWriter;
nsCOMPtr<nsIFile> mrTmpFile;
nsCString mrFilename;
Expand Down Expand Up @@ -823,6 +827,8 @@ class FinishReportingCallback MOZ_FINAL : public nsIFinishReportingCallback
}

private:
~FinishReportingCallback() {}

nsCOMPtr<nsIFinishDumpingCallback> mFinishDumping;
nsCOMPtr<nsISupports> mFinishDumpingData;
};
Expand Down
4 changes: 2 additions & 2 deletions xpcom/base/nsMemoryInfoDumper.h
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions xpcom/base/nsMemoryReporterManager.cpp
Expand Up @@ -118,6 +118,8 @@ ResidentUniqueDistinguishedAmount(int64_t* aN)

class ResidentUniqueReporter MOZ_FINAL : public nsIMemoryReporter
{
~ResidentUniqueReporter() {}

public:
NS_DECL_ISUPPORTS

Expand Down Expand Up @@ -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

Expand All @@ -583,6 +587,8 @@ NS_IMPL_ISUPPORTS(VsizeReporter, nsIMemoryReporter)

class ResidentReporter MOZ_FINAL : public nsIMemoryReporter
{
~ResidentReporter() {}

public:
NS_DECL_ISUPPORTS

Expand Down Expand Up @@ -615,6 +621,8 @@ NS_IMPL_ISUPPORTS(ResidentReporter, nsIMemoryReporter)

class PageFaultsSoftReporter MOZ_FINAL : public nsIMemoryReporter
{
~PageFaultsSoftReporter() {}

public:
NS_DECL_ISUPPORTS

Expand Down Expand Up @@ -657,6 +665,8 @@ PageFaultsHardDistinguishedAmount(int64_t* aAmount)

class PageFaultsHardReporter MOZ_FINAL : public nsIMemoryReporter
{
~PageFaultsHardReporter() {}

public:
NS_DECL_ISUPPORTS

Expand Down Expand Up @@ -704,6 +714,8 @@ HeapOverheadRatio(jemalloc_stats_t* aStats)

class JemallocHeapReporter MOZ_FINAL : public nsIMemoryReporter
{
~JemallocHeapReporter() {}

public:
NS_DECL_ISUPPORTS

Expand Down Expand Up @@ -808,6 +820,8 @@ class AtomTablesReporter MOZ_FINAL : public nsIMemoryReporter
{
MOZ_DEFINE_MALLOC_SIZE_OF(MallocSizeOf)

~AtomTablesReporter() {}

public:
NS_DECL_ISUPPORTS

Expand Down Expand Up @@ -1443,6 +1457,8 @@ nsMemoryReporterManager::UnblockRegistrationAndRestoreOriginalReporters()
// passed to nsIMemoryReporter::CollectReports.
class Int64Wrapper MOZ_FINAL : public nsISupports
{
~Int64Wrapper() {}

public:
NS_DECL_ISUPPORTS
Int64Wrapper() : mValue(0)
Expand All @@ -1455,6 +1471,8 @@ NS_IMPL_ISUPPORTS0(Int64Wrapper)

class ExplicitCallback MOZ_FINAL : public nsIHandleReportCallback
{
~ExplicitCallback() {}

public:
NS_DECL_ISUPPORTS

Expand Down
3 changes: 2 additions & 1 deletion xpcom/base/nsMemoryReporterManager.h
Expand Up @@ -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()
Expand Down
8 changes: 4 additions & 4 deletions xpcom/base/nsMessageLoop.cpp
Expand Up @@ -34,16 +34,15 @@ class MessageLoopIdleTask
public:
MOZ_DECLARE_REFCOUNTED_TYPENAME(MessageLoopIdleTask)
MessageLoopIdleTask(nsIRunnable* aTask, uint32_t aEnsureRunsAfterMS);
virtual ~MessageLoopIdleTask()
{
}
virtual void Run();

private:
nsresult Init(uint32_t aEnsureRunsAfterMS);

nsCOMPtr<nsIRunnable> mTask;
nsCOMPtr<nsITimer> mTimer;

virtual ~MessageLoopIdleTask() {}
};

/**
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions xpcom/base/nsMessageLoop.h
Expand Up @@ -15,6 +15,7 @@ class nsMessageLoop : public nsIMessageLoop
NS_DECL_ISUPPORTS
NS_DECL_NSIMESSAGELOOP

private:
virtual ~nsMessageLoop()
{
}
Expand Down
9 changes: 5 additions & 4 deletions xpcom/base/nsStatusReporterManager.h
Expand Up @@ -17,12 +17,12 @@ class nsStatusReporter MOZ_FINAL : public nsIStatusReporter

nsStatusReporter(nsACString& aProcess, nsACString& aDesc);

virtual ~nsStatusReporter();

protected:
private:
nsCString sProcess;
nsCString sName;
nsCString sDesc;

virtual ~nsStatusReporter();
};


Expand All @@ -33,8 +33,9 @@ class nsStatusReporterManager : public nsIStatusReporterManager
NS_DECL_NSISTATUSREPORTERMANAGER

nsStatusReporterManager();
virtual ~nsStatusReporterManager();

private:
nsCOMArray<nsIStatusReporter> mReporters;

virtual ~nsStatusReporterManager();
};
2 changes: 2 additions & 0 deletions xpcom/base/nsVersionComparatorImpl.h
Expand Up @@ -10,6 +10,8 @@

class nsVersionComparatorImpl MOZ_FINAL : public nsIVersionComparator
{
~nsVersionComparatorImpl() {}

public:
NS_DECL_ISUPPORTS
NS_DECL_NSIVERSIONCOMPARATOR
Expand Down

0 comments on commit 81effa4

Please sign in to comment.