In some implementations, specifically on musl, calloc() calls malloc() internally, and posix_memalign() calls aligned_alloc(). Detect such cases to prevent double-accounting.
| 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. |
| 121 | static 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 |
no test coverage detected