njn | 47363ab | 2003-04-21 13:24:40 +0000 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <stdlib.h> |
sewardj | 2e261a3 | 2005-05-12 18:01:15 +0000 | [diff] [blame] | 3 | #include <assert.h> |
njn | 47363ab | 2003-04-21 13:24:40 +0000 | [diff] [blame] | 4 | #include "../memcheck.h" |
| 5 | |
| 6 | int main(void) |
| 7 | { |
| 8 | int x; |
| 9 | int y = 0; |
| 10 | int* reachable; |
| 11 | int* dubious; |
| 12 | int* leaked; |
tom | 0c84ad2 | 2005-05-24 07:22:13 +0000 | [diff] [blame] | 13 | long n_reachable = 0; |
| 14 | long n_dubious = 0; |
| 15 | long n_leaked = 0; |
| 16 | long n_suppressed = 0; |
njn | 47363ab | 2003-04-21 13:24:40 +0000 | [diff] [blame] | 17 | |
sewardj | 2e261a3 | 2005-05-12 18:01:15 +0000 | [diff] [blame] | 18 | /* we require these longs to have same size as a machine word */ |
| 19 | assert(sizeof(long) == sizeof(void*)); |
| 20 | |
njn | 47363ab | 2003-04-21 13:24:40 +0000 | [diff] [blame] | 21 | /* Error counting */ |
| 22 | printf("errors: %d\n", VALGRIND_COUNT_ERRORS); |
| 23 | |
| 24 | if (x == 0) { |
| 25 | y++; |
| 26 | } else { |
| 27 | y--; |
| 28 | } |
| 29 | |
| 30 | printf("errors: %d\n", VALGRIND_COUNT_ERRORS); |
| 31 | |
| 32 | /* Leak checking */ |
| 33 | VALGRIND_DO_LEAK_CHECK; |
| 34 | VALGRIND_COUNT_LEAKS(n_leaked, n_dubious, n_reachable, n_suppressed); |
sewardj | 0b666d8 | 2003-07-08 00:13:51 +0000 | [diff] [blame] | 35 | if (n_reachable == 24) n_reachable = 0; /* handle glibc differences */ |
tom | 0c84ad2 | 2005-05-24 07:22:13 +0000 | [diff] [blame] | 36 | printf("leaks: %ldB, %ldB, %ldB, %ldB\n", |
njn | 47363ab | 2003-04-21 13:24:40 +0000 | [diff] [blame] | 37 | n_leaked, n_dubious, n_reachable, n_suppressed); |
| 38 | |
| 39 | leaked = malloc(77); |
| 40 | leaked = 0; |
| 41 | |
| 42 | dubious = malloc(88); |
| 43 | dubious += 10; |
| 44 | |
| 45 | reachable = malloc(99); |
| 46 | |
| 47 | VALGRIND_DO_LEAK_CHECK; |
njn | e8b5c05 | 2003-07-22 22:03:58 +0000 | [diff] [blame] | 48 | VALGRIND_DO_LEAK_CHECK; |
njn | 47363ab | 2003-04-21 13:24:40 +0000 | [diff] [blame] | 49 | VALGRIND_COUNT_LEAKS(n_leaked, n_dubious, n_reachable, n_suppressed); |
thughes | 48841f0 | 2004-10-31 11:31:16 +0000 | [diff] [blame] | 50 | if (n_reachable == 123) n_reachable = 99; /* handle glibc differences */ |
tom | 0c84ad2 | 2005-05-24 07:22:13 +0000 | [diff] [blame] | 51 | printf("leaks: %ldB, %ldB, %ldB, %ldB\n", |
njn | 47363ab | 2003-04-21 13:24:40 +0000 | [diff] [blame] | 52 | n_leaked, n_dubious, n_reachable, n_suppressed); |
| 53 | |
| 54 | printf("errors: %d\n", VALGRIND_COUNT_ERRORS); |
| 55 | |
| 56 | return 0; |
| 57 | } |