8 #define STRC(v) printf("==new %p from %p sz %jd\n", v, __builtin_return_address(0), n)
9 #define STRD(v) printf("==del %p from %p\n", v, __builtin_return_address(0))
10 void *operator new(size_t n) { void *vp = malloc(n); STRC(vp); bzero(vp,n); return vp; }
11 void operator delete(void *t) { STRD(t); free(t); }
12 void operator delete(void *t,size_t n) { STRD(t); free(t); }
13 void *operator new[](size_t n) { void *vp = malloc(n); STRC(vp); bzero(vp,n); return vp; }
14 void operator delete[](void *t) { STRD(t); free(t); }
15 void operator delete[](void *t,size_t n) { STRD(t); free(t); }
22 int64_t adr, from, sz;
23 blob(int64_t adr, int64_t from, int64_t sz) {
24 this->adr = adr; this->from = from; this->sz = sz;
27 typedef map<int64_t, blob*> recd_map;
28 typedef recd_map::value_type recd_val;
29 typedef recd_map::iterator recd_it;
31 int main(int ac, char **av)
33 int64_t adr, from, sz;
38 while( fgets(line,sizeof(line),fp) ) {
39 if( line[0] != '=' ) continue;
40 if( line[1] != '=' ) continue;
41 if( sscanf(line, "==new %jx from %jx sz %jd\n", &adr, &from, &sz) == 3 ) {
42 recds.insert(recd_val(adr, new blob(adr,from,sz)));
45 if( sscanf(line, "==del %jx from %jx\n", &adr, &from) == 2 ) {
46 recd_it ri = recds.lower_bound(adr);
47 if( ri == recds.end() || ri->first != adr ) {
48 printf("del miss adr %jx\n", adr);
55 int64_t n = recds.size(); sz = 0;
56 for( recd_it ri = recds.begin(); ri != recds.end(); ++ri ) sz += ri->second->sz;
57 printf("in use: %jd sz %jd\n", n, sz);
60 for( recd_it ri = recds.begin(); ri != recds.end(); ++ri ) {
61 adr = ri->second->adr; from = ri->second->from; sz = ri->second->sz;
62 recd_it li = leaks.lower_bound(from);
63 if( li == leaks.end() || li->first != from ) {
64 leaks.insert(recd_val(from, new blob(adr,from,sz)));
71 for( recd_it li = leaks.begin(); li != leaks.end(); ++li,++n ) {
72 printf("==leak at %jx sz %jd\n", li->second->from, li->second->sz);
75 printf("leakers: %jd/%jd sz %jd\n", leaks.size(), n, sz);