njn | 47363ab | 2003-04-21 13:24:40 +0000 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <stdlib.h> |
| 3 | #include "../memcheck.h" |
| 4 | |
| 5 | int main(void) |
| 6 | { |
| 7 | int x; |
| 8 | int y = 0; |
| 9 | int* reachable; |
| 10 | int* dubious; |
| 11 | int* leaked; |
| 12 | int n_reachable = 0; |
| 13 | int n_dubious = 0; |
| 14 | int n_leaked = 0; |
| 15 | int n_suppressed = 0; |
njn | 47363ab | 2003-04-21 13:24:40 +0000 | [diff] [blame] | 16 | |
| 17 | /* Error counting */ |
| 18 | printf("errors: %d\n", VALGRIND_COUNT_ERRORS); |
| 19 | |
| 20 | if (x == 0) { |
| 21 | y++; |
| 22 | } else { |
| 23 | y--; |
| 24 | } |
| 25 | |
| 26 | printf("errors: %d\n", VALGRIND_COUNT_ERRORS); |
| 27 | |
| 28 | /* Leak checking */ |
| 29 | VALGRIND_DO_LEAK_CHECK; |
| 30 | VALGRIND_COUNT_LEAKS(n_leaked, n_dubious, n_reachable, n_suppressed); |
sewardj | 0b666d8 | 2003-07-08 00:13:51 +0000 | [diff] [blame] | 31 | if (n_reachable == 24) n_reachable = 0; /* handle glibc differences */ |
njn | 47363ab | 2003-04-21 13:24:40 +0000 | [diff] [blame] | 32 | printf("leaks: %dB, %dB, %dB, %dB\n", |
| 33 | n_leaked, n_dubious, n_reachable, n_suppressed); |
| 34 | |
| 35 | leaked = malloc(77); |
| 36 | leaked = 0; |
| 37 | |
| 38 | dubious = malloc(88); |
| 39 | dubious += 10; |
| 40 | |
| 41 | reachable = malloc(99); |
| 42 | |
| 43 | VALGRIND_DO_LEAK_CHECK; |
njn | e8b5c05 | 2003-07-22 22:03:58 +0000 | [diff] [blame] | 44 | VALGRIND_DO_LEAK_CHECK; |
njn | 47363ab | 2003-04-21 13:24:40 +0000 | [diff] [blame] | 45 | VALGRIND_COUNT_LEAKS(n_leaked, n_dubious, n_reachable, n_suppressed); |
sewardj | 0b666d8 | 2003-07-08 00:13:51 +0000 | [diff] [blame] | 46 | if (n_reachable == 147) n_reachable = 99; /* handle glibc differences */ |
njn | 47363ab | 2003-04-21 13:24:40 +0000 | [diff] [blame] | 47 | printf("leaks: %dB, %dB, %dB, %dB\n", |
| 48 | n_leaked, n_dubious, n_reachable, n_suppressed); |
| 49 | |
| 50 | printf("errors: %d\n", VALGRIND_COUNT_ERRORS); |
| 51 | |
| 52 | return 0; |
| 53 | } |