Commit Diff


commit - be8b4b397af631bad302ef2646477f228b4537b5
commit + ca6a2d95acc005ef9a50e3f962ef0bbaa7876751
blob - 567b6770f34ffe291c3d061bebb9ef47dab6935a
blob + 789c963b5eb423d68772b978a547559fbc3505d4
--- src/cmd/9pfuse/main.c
+++ src/cmd/9pfuse/main.c
@@ -825,24 +825,26 @@ fusereaddir(FuseMsg *m)
 	p = buf;
 	ep = buf + n;
 	for(;;){
-		if(ff->nd == 0){
-			free(ff->d0);
-			ff->d0 = nil;
-			ff->d = nil;
-			if((ff->nd = fsdirread(ff->fid, &ff->d0)) < 0){
-				replyfuseerrstr(m);
-				return;
-			}
-			if(ff->nd == 0)
-				break;
-			ff->d = ff->d0;
-		}
-		while(ff->nd > 0 && canpack(ff->d, ff->off, &p, ep)){
+		while(ff->nd > 0){
+			if(!canpack(ff->d, ff->off, &p, ep))
+				goto out;
 			ff->off++;
 			ff->d++;
 			ff->nd--;
 		}
-	}				
+		free(ff->d0);
+		ff->d0 = nil;
+		ff->d = nil;
+		if((ff->nd = fsdirread(ff->fid, &ff->d0)) < 0){
+			replyfuseerrstr(m);
+			free(buf);
+			return;
+		}
+		if(ff->nd == 0)
+			break;
+		ff->d = ff->d0;
+	}
+out:			
 	replyfuse(m, buf, p - buf);
 	free(buf);
 }