extern "C" void malloc_debug_finalize(int malloc_debug_level) { // We only track leaks at level 10. if (malloc_debug_level == 10) { ReportMemoryLeaks(); } if (g_backtrace_enabled) { backtrace_shutdown(); } pthread_setspecific(g_debug_calls_disabled, NULL); }
static void mutex_lock_checked(MutexInfo* mrl, MutexInfo* object) { pid_t tid = gettid(); if (object->owner == tid) { object->lockCount++; return; } object->owner = tid; object->lockCount = 0; if (sPthreadDebugLevel >= CAPTURE_CALLSTACK) { // always record the call stack when acquiring a lock. // it's not efficient, but is useful during diagnostics object->stackDepth = get_backtrace(object->stackTrace, STACK_TRACE_DEPTH); } // no other locks held in this thread -- no deadlock possible! if (mrl == NULL) return; // check if the lock we're trying to acquire is a direct descendant of // the most recently locked mutex in this thread, in which case we're // in a good situation -- no deadlock possible if (historyListHas(&mrl->children, object) >= 0) return; pthread_mutex_lock_unchecked(&sDbgLock); linkParentToChild(mrl, object); if (!traverseTree(object, mrl)) { backtrace_shutdown(); LOGW("%s\n", kEndBanner); unlinkParentFromChild(mrl, object); // reenable pthread debugging for this thread sPthreadDebugDisabledThread = -1; } else { // record the call stack for this link // NOTE: the call stack is added at the same index // as mrl in object->parents[] // ie: object->parents.count == object->stacks.count, which is // also the index. if (sPthreadDebugLevel >= CAPTURE_CALLSTACK) { callstackListAdd(&object->stacks, object->stackDepth, object->stackTrace); } } pthread_mutex_unlock_unchecked(&sDbgLock); }
void debug_finalize() { if (g_debug == nullptr) { return; } if (g_debug->config().options & FREE_TRACK) { g_debug->free_track->VerifyAll(); } if (g_debug->config().options & LEAK_TRACK) { g_debug->track->DisplayLeaks(); } DebugDisableSet(true); backtrace_shutdown(); delete g_debug; g_debug = nullptr; DebugDisableFinalize(); }
extern "C" void malloc_debug_finalize() { ReportMemoryLeaks(); backtrace_shutdown(); }