From 87b6c95f6cc79d56034845975e74bd630f61dd78 Mon Sep 17 00:00:00 2001 From: Jim Chen Date: Thu, 24 Jul 2014 22:33:45 -0400 Subject: [PATCH] Bug 1016629 - b. Use RAII class to assign mStackToFill; r=snorp --- xpcom/threads/ThreadStackHelper.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/xpcom/threads/ThreadStackHelper.cpp b/xpcom/threads/ThreadStackHelper.cpp index b843eed2ba7..bb21ca152e2 100644 --- a/xpcom/threads/ThreadStackHelper.cpp +++ b/xpcom/threads/ThreadStackHelper.cpp @@ -109,6 +109,18 @@ ThreadStackHelper::~ThreadStackHelper() #endif } +namespace { +template +class ScopedSetPtr +{ +private: + T*& mPtr; +public: + ScopedSetPtr(T*& p, T* val) : mPtr(p) { mPtr = val; } + ~ScopedSetPtr() { mPtr = nullptr; } +}; +} + void ThreadStackHelper::GetStack(Stack& aStack) { @@ -118,6 +130,8 @@ ThreadStackHelper::GetStack(Stack& aStack) return; } + ScopedSetPtr stackPtr(mStackToFill, &aStack); + #if defined(XP_LINUX) if (!sInitialized) { MOZ_ASSERT(false); @@ -199,7 +213,6 @@ ThreadStackHelper::PrepareStackBuffer(Stack& aStack) !aStack.EnsureBufferCapacity(mMaxBufferSize)) { return false; } - mStackToFill = &aStack; return true; #else return false;