kernel: avoid waserror() botch in devwalk (from drawterm, thanks aiju)
calculate alloc flag before waserror(), as compilers like gcc will not notice the value changing later because setjump() restores the old value due to callee-saves. change is applies here to make it easier to merge with drawterm. thanks to aiju for debugging this; used to cause drawterm memory leak until compiled with gcc -O0.
This commit is contained in:
parent
30c05fe3dd
commit
00fbdd622a
|
@ -176,7 +176,7 @@ devwalk(Chan *c, Chan *nc, char **name, int nname, Dirtab *tab, int ntab, Devgen
|
||||||
if(nname > 0)
|
if(nname > 0)
|
||||||
isdir(c);
|
isdir(c);
|
||||||
|
|
||||||
alloc = 0;
|
alloc = (nc == nil);
|
||||||
wq = smalloc(sizeof(Walkqid)+(nname-1)*sizeof(Qid));
|
wq = smalloc(sizeof(Walkqid)+(nname-1)*sizeof(Qid));
|
||||||
if(waserror()){
|
if(waserror()){
|
||||||
if(alloc && wq->clone != nil)
|
if(alloc && wq->clone != nil)
|
||||||
|
@ -184,10 +184,9 @@ devwalk(Chan *c, Chan *nc, char **name, int nname, Dirtab *tab, int ntab, Devgen
|
||||||
free(wq);
|
free(wq);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
if(nc == nil){
|
if(alloc){
|
||||||
nc = devclone(c);
|
nc = devclone(c);
|
||||||
nc->type = 0; /* device doesn't know about this channel yet */
|
nc->type = 0; /* device doesn't know about this channel yet */
|
||||||
alloc = 1;
|
|
||||||
}
|
}
|
||||||
wq->clone = nc;
|
wq->clone = nc;
|
||||||
|
|
||||||
|
@ -252,7 +251,7 @@ Done:
|
||||||
if(alloc)
|
if(alloc)
|
||||||
cclose(wq->clone);
|
cclose(wq->clone);
|
||||||
wq->clone = nil;
|
wq->clone = nil;
|
||||||
}else if(wq->clone){
|
}else if(wq->clone != nil){
|
||||||
/* attach cloned channel to same device */
|
/* attach cloned channel to same device */
|
||||||
wq->clone->type = c->type;
|
wq->clone->type = c->type;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue