bg = makebackground(nil, acolorval(tok, Abgcolor, di->background.color));
bgurl = aurlval(tok, Abackground, nil, di->base);
if(bgurl != nil) {
- if(di->backgrounditem != nil)
- freeitem((Item*)di->backgrounditem);
- // really should remove old item from di->images list,
- // but there should only be one BODY element ...
+ if(di->backgrounditem != nil){
+ Iimage **ii;
+ for(ii=&di->images; *ii != nil; ii = &((*ii)->nextimage)){
+ if(*ii == di->backgrounditem){
+ *ii = di->backgrounditem->nextimage;
+ break;
+ }
+ }
+ freeitem(di->backgrounditem);
+ }
di->backgrounditem = (Iimage*)newiimage(bgurl, nil, ALnone, 0, 0, 0, 0, 0, 0, nil);
di->backgrounditem->nextimage = di->images;
di->images = di->backgrounditem;
fprint(2, "warning: unexpected </CAPTION>\n");
continue;
}
+ if(curtab->caption != nil)
+ freeitems(curtab->caption);
curtab->caption = ps->items->next;
- free(ps);
+ ps->items->next = nil;
+ freepstate(ps);
ps = nextps;
break;
fprint(2, "warning: empty row\n");
curtab->rows = tr->next;
tr->next = nil;
+ free(tr);
}
else
tr->flags = 0;
// note: ans may be nil and di->kids not nil, if there's a frameset!
outerps->items = newispacer(ISPnull);
outerps->lastit = outerps->items;
+ outerps->prelastit = nil;
is->psstk = ps;
if(ans != nil && di->hasscripts) {
// TODO evalscript(nil);
else
printitems(ans, "getitems returning:");
}
+ _freetokens(toks, tokslen);
return ans;
}
fprint(2, "warning: parse state stack is wrong\n");
}
else {
+ if(c->content != nil)
+ freeitems(c->content);
c->content = psstk->items->next;
+ psstk->items->next = nil;
c->flags &= ~TFparsing;
freepstate(psstk);
psstk = psstknext;
if(ps->skipping) {
if(warn)
fprint(2, "warning: skipping item: %I\n", it);
+ freeitem(it);
return;
}
it->anchorid = ps->curanchor;
// try to avoid making empty items
// but not crucial f the occasional one gets through
if(nl == 0 && ps->prelastit != nil) {
+ freeitems(ps->lastit);
ps->lastit = ps->prelastit;
ps->lastit->next = nil;
ps->prelastit = nil;
// copy the data from the allocated Tablerow into the array slot
t->rows[r] = *row;
rownext = row->next;
+ free(row);
row = &t->rows[r];
r--;
rcols = 0;
// If rowspan is > 1 but this is the last row,
// reset the rowspan
if(c != nil && c->rowspan > 1 && r == nrow-2)
- c->rowspan = 1;
+ c->rowspan = 1;
// reverse row->cells list (along nextinrow pointers)
row->cells = nil;
free(ga->style);
free(ga->title);
freescriptevents(ga->events);
+ free(ga);
}
free(it);
}
free(ff->name);
free(ff->value);
+ freeitem(ff->image);
for(o = ff->options; o != nil; o = onext) {
onext = o->next;
free(o->value);
for(c = t->cells; c != nil; c = cnext) {
cnext = c->next;
freeitems(c->content);
+ free(c);
}
if(t->grid != nil) {
for(i = 0; i < t->nrow; i++)
return;
free(d->src);
free(d->base);
- freeitem((Item*)d->backgrounditem);
+ free(d->doctitle);
+ freeitem(d->backgrounditem);
free(d->refresh);
freekidinfos(d->kidinfo);
freeanchors(d->anchors);
free(d);
}
-// Currently, someone else owns all the memory
-// pointed to by things in a Pstate.
static void
freepstate(Pstate* p)
{
+ freeitems(p->items);
free(p);
}
for(p = pshead; p != nil; p = pnext) {
pnext = p->next;
- free(p);
+ freepstate(p);
}
}
a = 0;
if(ts->mtype == TextHtml) {
for(;;) {
+ assert(ai <= alen);
if(alen - ai < ToksChunk/32) {
alen += ToksChunk;
a = erealloc(a, alen*sizeof *a);
else {
// plain text (non-html) tokens
for(;;) {
+ assert(ai <= alen);
if(alen - ai < ToksChunk/32) {
alen += ToksChunk;
a = erealloc(a, alen*sizeof *a);
memcpy(&s[i], buf, j*sizeof *s);
s[i+j] = 0;
}
+ setmalloctag(s, getcallerpc(&s));
return s;
}
Token* tok;
Rune buf[BIGBUFSIZE];
+ al = nil;
rbra = 0;
nexti = ts->i;
tok = &a[*pai];
else
tok->text = _Strndup(buf, i); // for warning print, in build
// attribute gathering loop
- al = nil;
while(1) {
// look for "ws name" or "ws name ws = ws val" (ws=whitespace)
// skip whitespace
if(warn)
fprint(2, "warning: incomplete tag at end of page\n");
backup(ts, nexti);
+ freeattrs(al);
tok->tag = Data;
tok->text = _Strdup(L"<");
return Data;
ans->attid = attid;
ans->value = value;
ans->next = link;
+ setmalloctag(ans, getcallerpc(&attid));
return ans;
}
Rune*
_Strdup(Rune* s)
{
+ Rune* ans;
if(s == nil)
return nil;
- return _Strndup(s, runestrlen(s));
+ ans = _Strndup(s, runestrlen(s));
+ setmalloctag(ans, getcallerpc(&s));
+ return ans;
}
// emalloc and copy n chars of s (assume s is at least that long),
ans = _newstr(n);
memmove(ans, s, n*sizeof(Rune));
ans[n] = 0;
+ setmalloctag(ans, getcallerpc(&s));
return ans;
}
// emalloc enough room for n Runes, plus 1 null terminator.
Rune*
_newstr(int n)
{
- return (Rune*)emalloc((n+1)*sizeof(Rune));
+ Rune* ans;
+
+ ans = (Rune*)emalloc((n+1)*sizeof(Rune));
+ setmalloctag(ans, getcallerpc(&n));
+ return ans;
}
// emalloc and copy s+t
p = _Stradd(ans, s, ns);
p = _Stradd(p, t, nt);
*p = 0;
+ setmalloctag(ans, getcallerpc(&s));
return ans;
}
if(start == stop)
return nil;
t = _Strndup(s+start, stop-start);
+ setmalloctag(t, getcallerpc(&s));
return t;
}
ans = nil;
assert(0);
}
+ setmalloctag(ans, getcallerpc(&buf));
return ans;
}
default:
assert(0);
}
+ setmalloctag(ans, getcallerpc(&buf));
return ans;
-
}