abaco: fix memory leaks

This commit is contained in:
cinap_lenrek 2013-09-04 21:27:59 +02:00
parent 32236b4957
commit cca9a1b523
2 changed files with 42 additions and 51 deletions

View file

@ -731,7 +731,7 @@ boxalloc(Line *l, Item *i, Rectangle r)
l->lastbox->next = b; l->lastbox->next = b;
} }
l->lastbox = b; l->lastbox = b;
setmalloctag(b, getcallerpc(&l));
return b; return b;
} }
@ -961,8 +961,9 @@ layitems(Item *items, Rectangle r, int laying)
void void
laypage(Page *p) laypage(Page *p)
{ {
settables(p);
layfree(p->lay); layfree(p->lay);
p->lay = nil;
settables(p);
p->lay = layitems(p->items, Rect(0,0,Dx(p->r),Dy(p->r)), TRUE); p->lay = layitems(p->items, Rect(0,0,Dx(p->r),Dy(p->r)), TRUE);
p->lay->r.max.y = max(p->lay->r.max.y, Dy(p->r)); p->lay->r.max.y = max(p->lay->r.max.y, Dy(p->r));
} }
@ -1015,16 +1016,17 @@ layfree(Lay *lay)
for(l=lay->lines; l!=nil; l=nextline){ for(l=lay->lines; l!=nil; l=nextline){
for(b=l->boxes; b!=nil; b=nextbox){ for(b=l->boxes; b!=nil; b=nextbox){
nextbox = b->next; nextbox = b->next;
if(b->i->tag==Iformfieldtag && istextfield(b->i)){ if(lay->laying==TRUE){
aux = &((Iformfield *)b->i)->aux; if(b->i->tag==Iformfieldtag && istextfield(b->i)){
if(*aux){ aux = &((Iformfield *)b->i)->aux;
textclose(*aux); if(*aux){
free(*aux); textclose(*aux);
} free(*aux);
*aux = nil; }
}else if(b->i->tag == Itabletag) *aux = nil;
laytablefree(((Itable *)b->i)->table); }else if(b->i->tag == Itabletag)
laytablefree(((Itable *)b->i)->table);
}
free(b); free(b);
} }
nextline = l->next; nextline = l->next;

View file

@ -443,10 +443,13 @@ initfontpaths(void)
{ {
Biobufhdr *bp; Biobufhdr *bp;
char buf[128]; char buf[128];
char *s;
int i; int i;
/* we don't care if getenv(2) fails */ /* we don't care if getenv(2) fails */
snprint(buf, sizeof(buf)-1, "%s/lib/abaco.fonts", getenv("home")); s = getenv("home");
snprint(buf, sizeof(buf)-1, "%s/lib/abaco.fonts", s);
free(s);
if((bp=Bopen(buf, OREAD)) == nil) if((bp=Bopen(buf, OREAD)) == nil)
goto Default; goto Default;
@ -658,66 +661,52 @@ validurl(Rune *r)
static void static void
execproc(void *v) execproc(void *v)
{ {
Channel *sync;
Exec *e; Exec *e;
int p[2], q[2];
char *cmd;
threadsetname("execproc"); threadsetname("execproc");
e = v; e = v;
p[0] = e->p[0];
p[1] = e->p[1];
q[0] = e->q[0];
q[1] = e->q[1];
cmd = e->cmd;
sync = e->sync;
rfork(RFFDG); rfork(RFFDG);
free(e); dup(e->p[0], 0);
dup(p[0], 0); close(e->p[0]);
close(p[0]); close(e->p[1]);
close(p[1]); if(e->q[0]){
if(q[0]){ dup(e->q[1], 1);
dup(q[1], 1); close(e->q[0]);
close(q[0]); close(e->q[1]);
close(q[1]);
} }
if(!procstderr) if(!procstderr)
close(2); close(2);
procexecl(sync, "/bin/rc", "rc", "-c", cmd, 0); procexecl(e->sync, "/bin/rc", "rc", "-c", e->cmd, 0);
error("can't exec"); error("can't exec");
} }
int int
pipeline(int fd, char *cmd, ...) pipeline(int fd, char *cmd, ...)
{ {
Channel *sync;
Exec *e; Exec *e;
int p[2], q[2];
va_list a; va_list a;
if(pipe(p)<0 || pipe(q)<0)
error("can't create pipe");
close(p[0]);
p[0] = fd;
sync = chancreate(sizeof(ulong), 0);
if(sync == nil)
error("can't create channel");
e = emalloc(sizeof(Exec)); e = emalloc(sizeof(Exec));
e->p[0] = p[0]; if(pipe(e->p)<0 || pipe(e->q)<0)
e->p[1] = p[1]; error("can't create pipe");
e->q[0] = q[0]; close(e->p[0]);
e->q[1] = q[1]; e->p[0] = fd;
va_start(a, cmd); va_start(a, cmd);
e->cmd = vsmprint(cmd, a); e->cmd = vsmprint(cmd, a);
va_end(a); va_end(a);
e->sync = sync; e->sync = chancreate(sizeof(ulong), 0);
if(e->sync == nil)
error("can't create channel");
proccreate(execproc, e, STACK); proccreate(execproc, e, STACK);
recvul(sync); recvul(e->sync);
chanfree(sync); chanfree(e->sync);
close(p[0]); free(e->cmd);
close(p[1]); close(e->p[0]);
close(q[1]); close(e->p[1]);
return q[0]; close(e->q[1]);
fd = e->q[0];
free(e);
return fd;
} }
static static