git: 9front

Download patch

ref: 4c7bfb500358721949e5fb767d112622a487ba0a
parent: a4ac136dc23986738b0461bcbcfda2266dd79bc6
author: cinap_lenrek <cinap_lenrek@centraldogma>
date: Wed Aug 10 13:26:05 EDT 2011

qio: fix block leak introduced by eqlock change

--- a/sys/src/9/port/qio.c
+++ b/sys/src/9/port/qio.c
@@ -1173,14 +1173,10 @@
 	}
 
 	dowakeup = 0;
-	eqlock(&q->wlock);
 	if(waserror()){
-		if(b != nil)
-			freeb(b);
-		qunlock(&q->wlock);
+		freeb(b);
 		nexterror();
 	}
-
 	ilock(q);
 
 	/* give up if the queue is closed */
@@ -1194,7 +1190,6 @@
 		if(q->noblock){
 			iunlock(q);
 			freeb(b);
-			qunlock(&q->wlock);
 			poperror();
 			return n;
 		}
@@ -1214,7 +1209,6 @@
 	q->len += BALLOC(b);
 	q->dlen += n;
 	QDEBUG checkb(b, "qbwrite");
-	b = nil;
 
 	/* make sure other end gets awakened */
 	if(q->state & Qstarve){
@@ -1222,6 +1216,7 @@
 		dowakeup = 1;
 	}
 	iunlock(q);
+	poperror();
 
 	/*  get output going again */
 	if(q->kick && (dowakeup || (q->state&Qkick)))
@@ -1255,12 +1250,17 @@
 		ilock(q);
 		q->state |= Qflow;
 		iunlock(q);
+
+		eqlock(&q->wlock);
+		if(waserror()){
+			qunlock(&q->wlock);
+			nexterror();
+		}
 		sleep(&q->wr, qnotfull, q);
+		qunlock(&q->wlock);
+		poperror();
 	}
-	USED(b);
 
-	qunlock(&q->wlock);
-	poperror();
 	return n;
 }
 
--