@@ -176,22 +176,19 @@ void MiniDumper::Initialize(const AsciiString& userDirPath)
176176 {
177177 // Something went wrong with the creation of the events..
178178 DEBUG_LOG ((" MiniDumper::Initialize: Unable to create events: error=%u" , ::GetLastError ()));
179- CleanupResources ();
180179 return ;
181180 }
182181
183182 m_dumpThread = ::CreateThread (NULL , 0 , MiniDumpThreadProc, this , CREATE_SUSPENDED, &m_dumpThreadId);
184183 if (!m_dumpThread)
185184 {
186185 DEBUG_LOG ((" MiniDumper::Initialize: Unable to create thread: error=%u" , ::GetLastError ()));
187- CleanupResources ();
188186 return ;
189187 }
190188
191- if (! ::ResumeThread (m_dumpThread))
189+ if (::ResumeThread (m_dumpThread) != 1 )
192190 {
193191 DEBUG_LOG ((" MiniDumper::Initialize: Unable to resume thread: error=%u" , ::GetLastError ()));
194- CleanupResources ();
195192 return ;
196193 }
197194
@@ -207,7 +204,7 @@ Bool MiniDumper::IsInitialized() const
207204Bool MiniDumper::IsDumpThreadStillRunning () const
208205{
209206 DWORD exitCode;
210- if (::GetExitCodeThread (m_dumpThread, &exitCode) && exitCode == STILL_ACTIVE)
207+ if (m_dumpThread != NULL && ::GetExitCodeThread (m_dumpThread, &exitCode) && exitCode == STILL_ACTIVE)
211208 {
212209 return true ;
213210 }
@@ -238,15 +235,50 @@ Bool MiniDumper::InitializeDumpDirectory(const AsciiString& userDirPath)
238235 return true ;
239236}
240237
241- void MiniDumper::CleanupResources ()
238+ void MiniDumper::ShutdownDumpThread ()
242239{
240+ if (IsDumpThreadStillRunning ())
241+ {
242+ DEBUG_ASSERTCRASH (m_quitting != NULL , (" MiniDumper::ShutdownDumpThread: Dump thread still running despite m_quitting being NULL" ));
243+ ::SetEvent (m_quitting);
244+
245+ DWORD waitRet = ::WaitForSingleObject (m_dumpThread, 3000 );
246+ if (waitRet != WAIT_OBJECT_0)
247+ {
248+ if (waitRet == WAIT_TIMEOUT)
249+ {
250+ DEBUG_LOG ((" MiniDumper::ShutdownDumpThread: Waiting for dumping thread to exit timed out, killing thread" , waitRet));
251+ ::TerminateThread (m_dumpThread, DUMPER_EXIT_FORCED_TERMINATE);
252+ }
253+ else if (waitRet == WAIT_FAILED)
254+ {
255+ DEBUG_LOG ((" MiniDumper::ShutdownDumpThread: Waiting for minidump triggering failed: status=%u, error=%u" , waitRet, ::GetLastError ()));
256+ }
257+ else
258+ {
259+ DEBUG_LOG ((" MiniDumper::ShutdownDumpThread: Waiting for minidump triggering failed: status=%u" , waitRet));
260+ }
261+ }
262+ }
263+ }
264+
265+ void MiniDumper::ShutDown ()
266+ {
267+ ShutdownDumpThread ();
268+
243269 if (m_dumpThread != NULL )
244270 {
245- DEBUG_ASSERTCRASH (!IsDumpThreadStillRunning (), (" MiniDumper::CleanupResources () called while Dump thread still active " ));
271+ DEBUG_ASSERTCRASH (!IsDumpThreadStillRunning (), (" MiniDumper::ShutDown: ShutdownDumpThread () was unable to stop Dump thread " ));
246272 ::CloseHandle (m_dumpThread);
247273 m_dumpThread = NULL ;
248274 }
249275
276+ if (m_quitting != NULL )
277+ {
278+ ::CloseHandle (m_quitting);
279+ m_quitting = NULL ;
280+ }
281+
250282 if (m_dumpComplete != NULL )
251283 {
252284 ::CloseHandle (m_dumpComplete);
@@ -259,52 +291,12 @@ void MiniDumper::CleanupResources()
259291 m_dumpRequested = NULL ;
260292 }
261293
262- if (m_quitting != NULL )
294+ if (m_loadedDbgHelp )
263295 {
264- ::CloseHandle (m_quitting);
265- m_quitting = NULL ;
266- }
267-
268- DbgHelpLoader::unload ();
269- m_loadedDbgHelp = false ;
270- }
271-
272- void MiniDumper::ShutDown ()
273- {
274- if (!m_miniDumpInitialized)
275- {
276- // Even if we failed to initialize, DbgHelpLoader could still have loaded its library
277- if (m_loadedDbgHelp)
278- {
279- DbgHelpLoader::unload ();
280- m_loadedDbgHelp = false ;
281- }
282-
283- return ;
284- }
285-
286- ::SetEvent (m_quitting);
287- DWORD waitRet = ::WaitForSingleObject (m_dumpThread, 3000 );
288- if (waitRet != WAIT_OBJECT_0)
289- {
290- if (waitRet == WAIT_TIMEOUT)
291- {
292- DEBUG_LOG ((" MiniDumper::ShutDown: Waiting for dumping thread to exit timed out, killing thread" , waitRet));
293- ::TerminateThread (m_dumpThread, DUMPER_EXIT_FORCED_TERMINATE);
294- }
295- else if (waitRet == WAIT_FAILED)
296- {
297- DEBUG_LOG ((" MiniDumper::ShutDown: Waiting for minidump triggering failed: status=%u, error=%u" , waitRet, ::GetLastError ()));
298- }
299- else
300- {
301- DEBUG_LOG ((" MiniDumper::ShutDown: Waiting for minidump triggering failed: status=%u" , waitRet));
302- }
303-
304- return ;
296+ DbgHelpLoader::unload ();
297+ m_loadedDbgHelp = false ;
305298 }
306299
307- CleanupResources ();
308300 m_miniDumpInitialized = false ;
309301}
310302
0 commit comments