From 5302e88796f0ad7fb2490e68b72ef6cd417dfb03 Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Sat, 2 Aug 2014 19:22:10 +0200 Subject: [PATCH] exportfs: simplify freefile() code remove impossible checks, rewrite as while loop. --- sys/src/cmd/exportfs/exportfs.c | 44 ++++++++++++++------------------- 1 file changed, 19 insertions(+), 25 deletions(-) diff --git a/sys/src/cmd/exportfs/exportfs.c b/sys/src/cmd/exportfs/exportfs.c index 24308dcc4..af0b6ac62 100644 --- a/sys/src/cmd/exportfs/exportfs.c +++ b/sys/src/cmd/exportfs/exportfs.c @@ -587,30 +587,25 @@ freefile(File *f) { File *parent, *child; -Loop: - f->ref--; - if(f->ref > 0) - return; - freecnt++; - if(f->ref < 0) abort(); - DEBUG(DFD, "free %s\n", f->name); - /* delete from parent */ - parent = f->parent; - if(parent->child == f) - parent->child = f->childlist; - else{ - for(child=parent->child; child->childlist!=f; child=child->childlist) - if(child->childlist == nil) - fatal("bad child list"); - child->childlist = f->childlist; + while(--f->ref == 0){ + freecnt++; + DEBUG(DFD, "free %s\n", f->name); + /* delete from parent */ + parent = f->parent; + if(parent->child == f) + parent->child = f->childlist; + else{ + for(child = parent->child; child->childlist != f; child = child->childlist) { + if(child->childlist == nil) + fatal("bad child list"); + } + child->childlist = f->childlist; + } + freeqid(f->qidt); + free(f->name); + free(f); + f = parent; } - freeqid(f->qidt); - free(f->name); - f->name = nil; - free(f); - f = parent; - if(f != nil) - goto Loop; } File * @@ -744,8 +739,7 @@ freeqid(Qidtab *q) ulong h; Qidtab *l; - q->ref--; - if(q->ref > 0) + if(--q->ref) return; qfreecnt++; h = qidhash(q->path);