Skip to content

Commit 0d6dcf7

Browse files
author
Snehasish Kumar
committed
Draft changes to demo free_sized test
1 parent c0fa432 commit 0d6dcf7

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

compiler-rt/lib/memprof/memprof_malloc_linux.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,24 @@ INTERCEPTOR(void, cfree, void *ptr) {
5050
}
5151
#endif // SANITIZER_INTERCEPT_CFREE
5252

53+
#if SANITIZER_INTERCEPT_FREE_SIZED
54+
INTERCEPTOR(void, free_sized, void *ptr, uptr size) {
55+
if (DlsymAlloc::PointerIsMine(ptr))
56+
return DlsymAlloc::Free(ptr);
57+
GET_STACK_TRACE_FREE;
58+
memprof_delete(ptr, size, 0, &stack, FROM_MALLOC);
59+
}
60+
#endif // SANITIZER_INTERCEPT_FREE_SIZED
61+
62+
#if SANITIZER_INTERCEPT_FREE_ALIGNED_SIZED
63+
INTERCEPTOR(void, free_aligned_sized, void *ptr, uptr alignment, uptr size) {
64+
if (DlsymAlloc::PointerIsMine(ptr))
65+
return DlsymAlloc::Free(ptr);
66+
GET_STACK_TRACE_FREE;
67+
memprof_delete(ptr, size, alignment, &stack, FROM_MALLOC);
68+
}
69+
#endif // SANITIZER_INTERCEPT_FREE_ALIGNED_SIZED
70+
5371
INTERCEPTOR(void *, malloc, uptr size) {
5472
if (DlsymAlloc::Use())
5573
return DlsymAlloc::Allocate(size);

compiler-rt/test/memprof/TestCases/memprof_histogram_uint8.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include <stdio.h>
99
#include <stdlib.h>
1010

11+
extern "C" void free_sized(void *p, size_t size);
12+
1113
int main() {
1214
// Allocate memory that will create a histogram
1315
char *buffer = (char *)malloc(1024);
@@ -28,7 +30,7 @@ int main() {
2830
}
2931

3032
// Free the memory to trigger MIB creation with histogram
31-
free(buffer);
33+
free_sized(buffer, 1024);
3234

3335
printf("Test completed successfully\n");
3436
return 0;

0 commit comments

Comments
 (0)