Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions compiler-rt/lib/memprof/memprof_malloc_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,24 @@ INTERCEPTOR(void, cfree, void *ptr) {
}
#endif // SANITIZER_INTERCEPT_CFREE

#if SANITIZER_INTERCEPT_FREE_SIZED
INTERCEPTOR(void, free_sized, void *ptr, uptr size) {
if (DlsymAlloc::PointerIsMine(ptr))
return DlsymAlloc::Free(ptr);
GET_STACK_TRACE_FREE;
memprof_delete(ptr, size, 0, &stack, FROM_MALLOC);
}
#endif // SANITIZER_INTERCEPT_FREE_SIZED

#if SANITIZER_INTERCEPT_FREE_ALIGNED_SIZED
INTERCEPTOR(void, free_aligned_sized, void *ptr, uptr alignment, uptr size) {
if (DlsymAlloc::PointerIsMine(ptr))
return DlsymAlloc::Free(ptr);
GET_STACK_TRACE_FREE;
memprof_delete(ptr, size, alignment, &stack, FROM_MALLOC);
}
#endif // SANITIZER_INTERCEPT_FREE_ALIGNED_SIZED

INTERCEPTOR(void *, malloc, uptr size) {
if (DlsymAlloc::Use())
return DlsymAlloc::Allocate(size);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <stdio.h>
#include <stdlib.h>

extern "C" void free_sized(void *p, size_t size);

int main() {
// Allocate memory that will create a histogram
char *buffer = (char *)malloc(1024);
Expand All @@ -28,7 +30,7 @@ int main() {
}

// Free the memory to trigger MIB creation with histogram
free(buffer);
free_sized(buffer, 1024);

printf("Test completed successfully\n");
return 0;
Expand Down
Loading