git: 9front

Download patch

ref: 9e66176cfe49be899c91cfd84c15b84fd09ff7e3
parent: 0f56788fcfd1fef22e1742d9a07a8f905cac372a
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Mon Jul 13 01:51:04 EDT 2015

httpfile: fix evictblock() so we wont consume all the memory

--- a/sys/src/cmd/ip/httpfile.c
+++ b/sys/src/cmd/ip/httpfile.c
@@ -114,11 +114,11 @@
 	for(l=&cache->first; (b=*l) != nil; l=&b->link){
 		if(b->rq != nil)	/* dont touch block when still requests queued */
 			continue;
-		if(b->rq != nil && (oldest == nil || (*oldest)->lastuse > b->lastuse))
+		if(oldest == nil || (*oldest)->lastuse > b->lastuse)
 			oldest = l;
 	}
 
-	if(oldest == nil)
+	if(oldest == nil || *oldest == nil || (*oldest)->rq != nil)
 		return;
 
 	b = *oldest;
@@ -439,8 +439,7 @@
 		b = recvp(finishchan);
 		assert(b == inprogress.first);
 		inprogress.first = b->link;
-		ncache++;
-		if(ncache >= mcache)
+		if(++ncache >= mcache)
 			evictblock(&cache);
 		addblock(&cache, b);
 		while((r = b->rq) != nil){
@@ -448,7 +447,7 @@
 			r->aux = nil;
 			readfrom(r, b);
 		}
-		if(inprogress.first)
+		if(inprogress.first != nil)
 			sendp(httpchan, inprogress.first);
 	}
 }
--