mirror of
git://git.9front.org/plan9front/plan9front
synced 2025-01-12 11:10:06 +00:00
devshr: fixed memory leaks / race condition
This commit is contained in:
parent
e1260aa4d6
commit
d2a1d1fb37
1 changed files with 13 additions and 13 deletions
|
@ -29,8 +29,12 @@ static void
|
|||
shrdecref(Shr *sp)
|
||||
{
|
||||
Mount *m, *mm;
|
||||
int n;
|
||||
|
||||
if(decref(sp) != 0)
|
||||
qlock(&shrlk);
|
||||
n = decref(sp);
|
||||
qunlock(&shrlk);
|
||||
if(n != 0)
|
||||
return;
|
||||
|
||||
for(m = sp->umh.mount; m != nil; m = mm) {
|
||||
|
@ -38,6 +42,8 @@ shrdecref(Shr *sp)
|
|||
mm = m->next;
|
||||
free(m);
|
||||
}
|
||||
if(sp->desc != nil)
|
||||
free(sp->desc);
|
||||
free(sp->owner);
|
||||
free(sp->name);
|
||||
free(sp);
|
||||
|
@ -491,6 +497,7 @@ shrread(Chan *c, void *va, long n, vlong off)
|
|||
}
|
||||
ret = readstr(off, va, n, sp->desc);
|
||||
qunlock(&sp->desclock);
|
||||
shrdecref(sp);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -511,19 +518,14 @@ shrwrite(Chan *c, void *va, long n, vlong)
|
|||
|
||||
qlock(&shrlk);
|
||||
sp = shrlookup(nil, c->qid.path);
|
||||
if(sp == nil) {
|
||||
qunlock(&shrlk);
|
||||
error(Enonexist);
|
||||
}
|
||||
incref(sp);
|
||||
if(sp != nil)
|
||||
incref(sp);
|
||||
qunlock(&shrlk);
|
||||
if(waserror()){
|
||||
shrdecref(sp);
|
||||
nexterror();
|
||||
}
|
||||
|
||||
if(sp == nil)
|
||||
error(Enonexist);
|
||||
buf = smalloc(n+1);
|
||||
if(waserror()){
|
||||
shrdecref(sp);
|
||||
free(buf);
|
||||
nexterror();
|
||||
}
|
||||
|
@ -542,7 +544,6 @@ shrwrite(Chan *c, void *va, long n, vlong)
|
|||
shrdecref(sp);
|
||||
free(buf);
|
||||
poperror();
|
||||
poperror();
|
||||
return n;
|
||||
}
|
||||
|
||||
|
@ -616,7 +617,6 @@ shrwrite(Chan *c, void *va, long n, vlong)
|
|||
shrdecref(sp);
|
||||
free(buf);
|
||||
poperror();
|
||||
poperror();
|
||||
return n;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue