mirror of
https://github.com/Zenithsiz/ftmemsim-valgrind.git
synced 2026-02-03 18:13:01 +00:00
returned (bytes leaked, dubious, etc) were incremented for every leak check performed. So if you called VALGRIND_DO_LEAK_CHECK twice in a row, the totals would be updated twice by the same amount. This was a bit silly. So now COUNT_LEAKS just returns the numbers of bytes leaked found from the previous leak check. I even updated the docs, and changed the regression test so old version fail but the new version passes (by doing two DO_LEAK_CHECKS in a row). git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1778
54 lines
1.2 KiB
C
54 lines
1.2 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include "../memcheck.h"
|
|
|
|
int main(void)
|
|
{
|
|
int x;
|
|
int y = 0;
|
|
int* reachable;
|
|
int* dubious;
|
|
int* leaked;
|
|
int n_reachable = 0;
|
|
int n_dubious = 0;
|
|
int n_leaked = 0;
|
|
int n_suppressed = 0;
|
|
|
|
/* Error counting */
|
|
printf("errors: %d\n", VALGRIND_COUNT_ERRORS);
|
|
|
|
if (x == 0) {
|
|
y++;
|
|
} else {
|
|
y--;
|
|
}
|
|
|
|
printf("errors: %d\n", VALGRIND_COUNT_ERRORS);
|
|
|
|
/* Leak checking */
|
|
VALGRIND_DO_LEAK_CHECK;
|
|
VALGRIND_COUNT_LEAKS(n_leaked, n_dubious, n_reachable, n_suppressed);
|
|
if (n_reachable == 24) n_reachable = 0; /* handle glibc differences */
|
|
printf("leaks: %dB, %dB, %dB, %dB\n",
|
|
n_leaked, n_dubious, n_reachable, n_suppressed);
|
|
|
|
leaked = malloc(77);
|
|
leaked = 0;
|
|
|
|
dubious = malloc(88);
|
|
dubious += 10;
|
|
|
|
reachable = malloc(99);
|
|
|
|
VALGRIND_DO_LEAK_CHECK;
|
|
VALGRIND_DO_LEAK_CHECK;
|
|
VALGRIND_COUNT_LEAKS(n_leaked, n_dubious, n_reachable, n_suppressed);
|
|
if (n_reachable == 147) n_reachable = 99; /* handle glibc differences */
|
|
printf("leaks: %dB, %dB, %dB, %dB\n",
|
|
n_leaked, n_dubious, n_reachable, n_suppressed);
|
|
|
|
printf("errors: %d\n", VALGRIND_COUNT_ERRORS);
|
|
|
|
return 0;
|
|
}
|