Lines Matching refs:pointer

85 ssize_t debug_malloc_backtrace(void* pointer, uintptr_t* frames, size_t frame_count);
87 size_t debug_malloc_usable_size(void* pointer);
89 void debug_free(void* pointer);
92 void* debug_realloc(void* pointer, size_t bytes);
213 static void LogError(const void* pointer, const char* error_str) { in LogError() argument
215 error_log("+++ ALLOCATION %p %s", pointer, error_str); in LogError()
220 PointerData::LogFreeBacktrace(pointer); in LogError()
231 static bool VerifyPointer(const void* pointer, const char* function_name) { in VerifyPointer() argument
233 Header* header = g_debug->GetHeader(pointer); in VerifyPointer()
242 LogError(pointer, error_str.c_str()); in VerifyPointer()
248 if (!PointerData::Exists(pointer)) { in VerifyPointer()
250 LogError(pointer, error_str.c_str()); in VerifyPointer()
257 static size_t InternalMallocUsableSize(void* pointer) { in InternalMallocUsableSize() argument
259 return g_debug->GetHeader(pointer)->usable_size; in InternalMallocUsableSize()
261 return g_dispatch->malloc_usable_size(pointer); in InternalMallocUsableSize()
404 size_t debug_malloc_usable_size(void* pointer) { in debug_malloc_usable_size() argument
405 if (DebugCallsDisabled() || pointer == nullptr) { in debug_malloc_usable_size()
406 return g_dispatch->malloc_usable_size(pointer); in debug_malloc_usable_size()
412 if (!VerifyPointer(pointer, "malloc_usable_size")) { in debug_malloc_usable_size()
416 return InternalMallocUsableSize(pointer); in debug_malloc_usable_size()
420 if ((g_debug->config().options() & BACKTRACE) && g_debug->pointer->ShouldDumpAndReset()) { in InternalMalloc()
442 void* pointer; in InternalMalloc() local
449 pointer = InitHeader(header, header, size); in InternalMalloc()
451 pointer = g_dispatch->malloc(real_size); in InternalMalloc()
454 if (pointer != nullptr) { in InternalMalloc()
456 PointerData::Add(pointer, size); in InternalMalloc()
460 size_t bytes = InternalMallocUsableSize(pointer); in InternalMalloc()
463 memset(pointer, g_debug->config().fill_alloc_value(), bytes); in InternalMalloc()
466 return pointer; in InternalMalloc()
477 void* pointer = InternalMalloc(size); in debug_malloc() local
480 g_debug->record->AddEntry(new MallocEntry(pointer, size)); in debug_malloc()
483 return pointer; in debug_malloc()
486 static void InternalFree(void* pointer) { in InternalFree() argument
487 if ((g_debug->config().options() & BACKTRACE) && g_debug->pointer->ShouldDumpAndReset()) { in InternalFree()
493 void* free_pointer = pointer; in InternalFree()
497 header = g_debug->GetHeader(pointer); in InternalFree()
515 bytes = g_dispatch->malloc_usable_size(pointer); in InternalFree()
521 memset(pointer, g_debug->config().fill_free_value(), bytes); in InternalFree()
525 PointerData::Remove(pointer); in InternalFree()
534 pointer = PointerData::AddFreed(pointer); in InternalFree()
535 if (pointer != nullptr) { in InternalFree()
537 pointer = g_debug->GetHeader(pointer)->orig_pointer; in InternalFree()
539 g_dispatch->free(pointer); in InternalFree()
546 void debug_free(void* pointer) { in debug_free() argument
547 if (DebugCallsDisabled() || pointer == nullptr) { in debug_free()
548 return g_dispatch->free(pointer); in debug_free()
555 g_debug->record->AddEntry(new FreeEntry(pointer)); in debug_free()
558 if (!VerifyPointer(pointer, "free")) { in debug_free()
562 InternalFree(pointer); in debug_free()
582 void* pointer; in debug_memalign() local
604 pointer = g_dispatch->malloc(real_size); in debug_memalign()
605 if (pointer == nullptr) { in debug_memalign()
609 uintptr_t value = reinterpret_cast<uintptr_t>(pointer) + g_debug->pointer_offset(); in debug_memalign()
614 pointer = InitHeader(header, pointer, bytes); in debug_memalign()
622 pointer = g_dispatch->memalign(alignment, real_size); in debug_memalign()
625 if (pointer != nullptr) { in debug_memalign()
627 PointerData::Add(pointer, bytes); in debug_memalign()
631 size_t bytes = InternalMallocUsableSize(pointer); in debug_memalign()
634 memset(pointer, g_debug->config().fill_alloc_value(), bytes); in debug_memalign()
638 g_debug->record->AddEntry(new MemalignEntry(pointer, bytes, alignment)); in debug_memalign()
642 return pointer; in debug_memalign()
645 void* debug_realloc(void* pointer, size_t bytes) { in debug_realloc() argument
647 return g_dispatch->realloc(pointer, bytes); in debug_realloc()
653 if (pointer == nullptr) { in debug_realloc()
654 pointer = InternalMalloc(bytes); in debug_realloc()
656 g_debug->record->AddEntry(new ReallocEntry(pointer, bytes, nullptr)); in debug_realloc()
658 return pointer; in debug_realloc()
661 if (!VerifyPointer(pointer, "realloc")) { in debug_realloc()
667 g_debug->record->AddEntry(new ReallocEntry(nullptr, bytes, pointer)); in debug_realloc()
670 InternalFree(pointer); in debug_realloc()
693 Header* header = g_debug->GetHeader(pointer); in debug_realloc()
697 PointerData::Remove(pointer); in debug_realloc()
698 PointerData::Add(pointer, real_size); in debug_realloc()
700 return pointer; in debug_realloc()
715 PointerData::Remove(pointer); in debug_realloc()
716 PointerData::Add(pointer, real_size); in debug_realloc()
718 return pointer; in debug_realloc()
729 memcpy(new_pointer, pointer, prev_size); in debug_realloc()
730 InternalFree(pointer); in debug_realloc()
733 PointerData::Remove(pointer); in debug_realloc()
736 prev_size = g_dispatch->malloc_usable_size(pointer); in debug_realloc()
737 new_pointer = g_dispatch->realloc(pointer, real_size); in debug_realloc()
759 g_debug->record->AddEntry(new ReallocEntry(new_pointer, bytes, pointer)); in debug_realloc()
796 void* pointer; in debug_calloc() local
805 pointer = InitHeader(header, header, size); in debug_calloc()
807 pointer = g_dispatch->calloc(1, real_size); in debug_calloc()
811 g_debug->record->AddEntry(new CallocEntry(pointer, bytes, nmemb)); in debug_calloc()
814 if (pointer != nullptr && g_debug->TrackPointers()) { in debug_calloc()
815 PointerData::Add(pointer, size); in debug_calloc()
817 return pointer; in debug_calloc()
908 if (g_debug->pointer) { in debug_malloc_disable()
909 g_debug->pointer->PrepareFork(); in debug_malloc_disable()
915 if (g_debug->pointer) { in debug_malloc_enable()
916 g_debug->pointer->PostForkParent(); in debug_malloc_enable()
921 ssize_t debug_malloc_backtrace(void* pointer, uintptr_t* frames, size_t max_frames) { in debug_malloc_backtrace() argument
922 if (DebugCallsDisabled() || pointer == nullptr) { in debug_malloc_backtrace()
932 pointer = UntagPointer(pointer); in debug_malloc_backtrace()
933 return PointerData::GetFrames(pointer, frames, max_frames); in debug_malloc_backtrace()