libndb: more memory accounting, fix leak tickled by dhcpd
[rsc] --rw-rw-r-- M 337084 glenda sys 4412 Apr 4 14:14 sys/include/ndb.h
/n/sourcesdump/2006/0404/plan9/sys/include/ndb.h:152,154 -
/n/sourcesdump/2006/0405/plan9/sys/include/ndb.h:152,155
void ndbsetval(Ndbtuple*, char*, int);
Ndbtuple* ndbsnext(Ndbs*, char*, char*);
Ndbtuple* ndbsubstitute(Ndbtuple*, Ndbtuple*, Ndbtuple*);
+ void ndbsetmalloctag(Ndbtuple*, uintptr);
[rsc] --rw-rw-r-- M 337084 glenda sys 1796 Apr 4 14:14 sys/src/libndb/csgetval.c
/n/sourcesdump/2006/0404/plan9/sys/src/libndb/csgetval.c:103,107 -
/n/sourcesdump/2006/0405/plan9/sys/src/libndb/csgetval.c:103,108
}
free(p);
}
+ ndbsetmalloctag(t, getcallerpc(&netroot));
return t;
}
[rsc] --rw-rw-r-- M 337084 glenda sys 1178 Apr 4 14:14 sys/src/libndb/csipinfo.c
/n/sourcesdump/2006/0404/plan9/sys/src/libndb/csipinfo.c:63,68 -
/n/sourcesdump/2006/0405/plan9/sys/src/libndb/csipinfo.c:63,68
}
close(fd);
- setmalloctag(first, getcallerpc(&netroot));
+ ndbsetmalloctag(first, getcallerpc(&netroot));
return first;
}
[rsc] --rw-rw-r-- M 337084 glenda sys 2883 Apr 4 14:14 sys/src/libndb/dnsquery.c
/n/sourcesdump/2006/0404/plan9/sys/src/libndb/dnsquery.c:63,68 -
/n/sourcesdump/2006/0405/plan9/sys/src/libndb/dnsquery.c:63,69
t = doquery(fd, val, type);
close(fd);
+ ndbsetmalloctag(t, getcallerpc(&net));
return t;
}
/n/sourcesdump/2006/0404/plan9/sys/src/libndb/dnsquery.c:151,156 -
/n/sourcesdump/2006/0405/plan9/sys/src/libndb/dnsquery.c:152,157
}
}
- setmalloctag(first, getcallerpc(&fd));
+ ndbsetmalloctag(first, getcallerpc(&fd));
return first;
}
[rsc] --rw-rw-r-- M 337084 glenda sys 1544 Apr 4 14:14 sys/src/libndb/ndbaux.c
/n/sourcesdump/2006/0404/plan9/sys/src/libndb/ndbaux.c:86,94 -
/n/sourcesdump/2006/0405/plan9/sys/src/libndb/ndbaux.c:86,95
last = t;
t->line = 0;
t->entry = 0;
+ setmalloctag(t, getcallerpc(&cp));
}
if(first)
last->line = first;
- setmalloctag(first, getcallerpc(&cp));
+ ndbsetmalloctag(first, getcallerpc(&cp));
return first;
}
[rsc] --rw-rw-r-- M 337084 glenda sys 2246 Apr 4 14:14 sys/src/libndb/ndbcache.c
/n/sourcesdump/2006/0404/plan9/sys/src/libndb/ndbcache.c:64,69 -
/n/sourcesdump/2006/0405/plan9/sys/src/libndb/ndbcache.c:64,70
last = to_t;
newline = from_t->line != from_t->entry;
}
+ ndbsetmalloctag(first, getcallerpc(&db));
return first;
}
/n/sourcesdump/2006/0404/plan9/sys/src/libndb/ndbcache.c:127,132 -
/n/sourcesdump/2006/0405/plan9/sys/src/libndb/ndbcache.c:128,134
*l = nil;
err:
ndbcachefree(c);
+ ndbsetmalloctag(t, getcallerpc(&db));
return t;
}
[rsc] --rw-rw-r-- M 337084 presotto sys 297 Apr 4 14:14 sys/src/libndb/ndbconcatenate.c
/n/sourcesdump/2006/0404/plan9/sys/src/libndb/ndbconcatenate.c:14,18 -
/n/sourcesdump/2006/0405/plan9/sys/src/libndb/ndbconcatenate.c:14,19
for(t = a; t->entry; t = t->entry)
;
t->entry = b;
+ ndbsetmalloctag(a, getcallerpc(&a));
return a;
}
[rsc] --rw-rw-r-- M 337084 presotto sys 474 Apr 4 14:14 sys/src/libndb/ndbdiscard.c
/n/sourcesdump/2006/0404/plan9/sys/src/libndb/ndbdiscard.c:25,29 -
/n/sourcesdump/2006/0405/plan9/sys/src/libndb/ndbdiscard.c:25,30
a->entry = nil;
ndbfree(a);
+ ndbsetmalloctag(t, getcallerpc(&t));
return t;
}
[rsc] --rw-rw-r-- M 337084 glenda sys 1123 Apr 4 14:14 sys/src/libndb/ndbfree.c
/n/sourcesdump/2006/0404/plan9/sys/src/libndb/ndbfree.c:61,65 -
/n/sourcesdump/2006/0405/plan9/sys/src/libndb/ndbfree.c:61,76
t->val = t->valbuf;
if(val != nil)
ndbsetval(t, val, strlen(val));
+ ndbsetmalloctag(t, getcallerpc(&attr));
return t;
+ }
+
+ /*
+ * set owner of a tuple
+ */
+ void
+ ndbsetmalloctag(Ndbtuple *t, uintptr tag)
+ {
+ for(; t; t=t->entry)
+ setmalloctag(t, tag);
}
[rsc] --rw-rw-r-- M 337084 presotto sys 876 Apr 4 14:14 sys/src/libndb/ndbgetipaddr.c
/n/sourcesdump/2006/0404/plan9/sys/src/libndb/ndbgetipaddr.c:16,21 -
/n/sourcesdump/2006/0405/plan9/sys/src/libndb/ndbgetipaddr.c:16,22
attr = ipattr(val);
if(strcmp(attr, "ip") == 0){
it = ndbnew("ip", val);
+ ndbsetmalloctag(it, getcallerpc(&db));
return it;
}
/n/sourcesdump/2006/0404/plan9/sys/src/libndb/ndbgetipaddr.c:43,47 -
/n/sourcesdump/2006/0405/plan9/sys/src/libndb/ndbgetipaddr.c:44,49
}
}
+ ndbsetmalloctag(first, getcallerpc(&db));
return first;
}
[rsc] --rw-rw-r-- M 337084 glenda sys 1348 Apr 4 14:14 sys/src/libndb/ndbgetval.c
/n/sourcesdump/2006/0404/plan9/sys/src/libndb/ndbgetval.c:71,75 -
/n/sourcesdump/2006/0405/plan9/sys/src/libndb/ndbgetval.c:71,76
}
free(p);
}
+ ndbsetmalloctag(t, getcallerpc(&db));
return t;
}
[rsc] --rw-rw-r-- M 337084 glenda sys 5276 Apr 4 14:14 sys/src/libndb/ndbhash.c
[diffs elided - too long]
[diff -c /n/sourcesdump/2006/0404/plan9/sys/src/libndb/ndbhash.c /n/sourcesdump/2006/0405/plan9/sys/src/libndb/ndbhash.c]
[rsc] --rw-rw-r-- M 337084 glenda sys 5105 Apr 4 14:14 sys/src/libndb/ndbipinfo.c
/n/sourcesdump/2006/0404/plan9/sys/src/libndb/ndbipinfo.c:40,45 -
/n/sourcesdump/2006/0405/plan9/sys/src/libndb/ndbipinfo.c:40,46
}
strncpy(t->attr, p, sizeof(t->attr)-1);
}
+ ndbsetmalloctag(first, getcallerpc(&argc));
return first;
}
/n/sourcesdump/2006/0404/plan9/sys/src/libndb/ndbipinfo.c:97,102 -
/n/sourcesdump/2006/0405/plan9/sys/src/libndb/ndbipinfo.c:98,104
if(nf->ptr & Ffound)
nf->ptr = (nf->ptr & ~Ffound) | Fignore;
+ ndbsetmalloctag(t, getcallerpc(&db));
return t;
}
/n/sourcesdump/2006/0404/plan9/sys/src/libndb/ndbipinfo.c:136,147 -
/n/sourcesdump/2006/0405/plan9/sys/src/libndb/ndbipinfo.c:138,152
else
ipmove(mask, defmask(net));
masklen = prefixlen(mask);
- if(masklen <= prefix)
+ if(masklen <= prefix){
t = ndbconcatenate(t, filter(db, nt, f));
- } else
- ndbfree(nt);
+ nt = nil;
+ }
+ }
+ ndbfree(nt);
nt = ndbsnext(&s, "ip", netstr);
}
+ ndbsetmalloctag(t, getcallerpc(&db));
return t;
}
/n/sourcesdump/2006/0404/plan9/sys/src/libndb/ndbipinfo.c:238,242 -
/n/sourcesdump/2006/0405/plan9/sys/src/libndb/ndbipinfo.c:243,248
}
ndbfree(f);
+ ndbsetmalloctag(t, getcallerpc(&db));
return t;
}
[rsc] --rw-rw-r-- M 337084 glenda sys 1207 Apr 4 14:14 sys/src/libndb/ndbparse.c
/n/sourcesdump/2006/0404/plan9/sys/src/libndb/ndbparse.c:44,49 -
/n/sourcesdump/2006/0405/plan9/sys/src/libndb/ndbparse.c:44,50
t = _ndbparseline(line);
if(t == 0)
continue;
+ setmalloctag(t, getcallerpc(&db));
if(first)
last->entry = t;
else
/n/sourcesdump/2006/0404/plan9/sys/src/libndb/ndbparse.c:52,57 -
/n/sourcesdump/2006/0405/plan9/sys/src/libndb/ndbparse.c:53,58
while(last->entry)
last = last->entry;
}
- setmalloctag(first, getcallerpc(&db));
+ ndbsetmalloctag(first, getcallerpc(&db));
return first;
}
[rsc] --rw-rw-r-- M 337084 presotto sys 867 Apr 4 14:14 sys/src/libndb/ndbsubstitute.c
/n/sourcesdump/2006/0404/plan9/sys/src/libndb/ndbsubstitute.c:9,18 -
/n/sourcesdump/2006/0405/plan9/sys/src/libndb/ndbsubstitute.c:9,23
{
Ndbtuple *nt;
- if(a == b)
+ if(a == b){
+ ndbsetmalloctag(t, getcallerpc(&t));
return t;
- if(b == nil)
- return ndbdiscard(t, a);
+ }
+ if(b == nil){
+ t = ndbdiscard(t, a);
+ ndbsetmalloctag(t, getcallerpc(&t));
+ return t;
+ }
/* all pointers to a become pointers to b */
for(nt = t; nt != nil; nt = nt->entry){
/n/sourcesdump/2006/0404/plan9/sys/src/libndb/ndbsubstitute.c:23,31 -
/n/sourcesdump/2006/0405/plan9/sys/src/libndb/ndbsubstitute.c:28,35
}
/* end of b chain points to a's successors */
- for(nt = b; nt->entry; nt = nt->entry){
+ for(nt = b; nt->entry; nt = nt->entry)
nt->line = nt->entry;
- }
nt->line = a->line;
nt->entry = a->entry;
/n/sourcesdump/2006/0404/plan9/sys/src/libndb/ndbsubstitute.c:32,39 -
/n/sourcesdump/2006/0405/plan9/sys/src/libndb/ndbsubstitute.c:36,46
a->entry = nil;
ndbfree(a);
- if(a == t)
+ if(a == t){
+ ndbsetmalloctag(b, getcallerpc(&t));
return b;
- else
+ }else{
+ ndbsetmalloctag(t, getcallerpc(&t));
return t;
+ }
}
|