-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample2.c
More file actions
37 lines (30 loc) · 1.03 KB
/
example2.c
File metadata and controls
37 lines (30 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <stdio.h>
#include "memtrack.h"
int example_init_callback(void *userdata, size_t malloc_count) {
printf("init: malloc_count = %zu\n", malloc_count);
// 0 = success, continue iteration
// non-zero = failure, abort iteration
return 0;
}
int example_malloc_callback(void *userdata, size_t realloc_count, size_t size, const char *file, int line) {
printf("malloc: realloc_count = %zu, size = %zu, %s:%i\n", realloc_count, size, file, line);
return 0;
}
int example_realloc_callback(void *userdata, size_t new_size, const char *file, int line) {
printf("realloc: new_size = %zu, %s:%i\n", new_size, file, line);
return 0;
}
int main() {
void *p = malloc(123);
p = realloc(p, 456);
void *q = malloc(654);
q = realloc(q, 321);
memtrack_iter_info info = {
.userdata = NULL,
.init_callback = example_init_callback,
.malloc_callback = example_malloc_callback,
.realloc_callback = example_realloc_callback
};
memtrack_iter_leaks(&info);
return 0;
}