MCPcopy Create free account
hub / github.com/async-profiler/async-profiler / detectNestedMalloc

Function detectNestedMalloc

src/mallocTracer.cpp:121–132  ·  view source on GitHub ↗

In some implementations, specifically on musl, calloc() calls malloc() internally, and posix_memalign() calls aligned_alloc(). Detect such cases to prevent double-accounting.

Source from the content-addressed store, hash-verified

119// In some implementations, specifically on musl, calloc() calls malloc() internally,
120// and posix_memalign() calls aligned_alloc(). Detect such cases to prevent double-accounting.
121static void detectNestedMalloc() {
122 CodeCache* libc = Profiler::instance()->findLibraryByAddress((void*)_orig_calloc);
123 if (libc == NULL) {
124 return;
125 }
126
127 libc->patchImport(im_malloc, (void*)nested_malloc_hook);
128
129 _current_thread = pthread_self();
130 free(_orig_calloc(1, 1));
131 _current_thread = pthread_t(0);
132}
133
134// Call each intercepted function at least once to ensure
135// its GOT entry is updated with a correct target address

Callers 1

initializeMethod · 0.85

Calls 2

findLibraryByAddressMethod · 0.80
patchImportMethod · 0.80

Tested by

no test coverage detected