shithub: riscv

Download patch

ref: d4414b3959fd289aaffcf0e10227b5860a0bb254
parent: 58533c35fb6164c655c6925544c3147701d27dca
author: cinap_lenrek <[email protected]>
date: Wed May 1 14:31:13 EDT 2013

devloopback: fix potential channel leak on allocation error (from eriks 9atom)

--- a/sys/src/9/port/devloopback.c
+++ b/sys/src/9/port/devloopback.c
@@ -131,8 +131,12 @@
 	}
 
 	c = devattach('X', spec);
-	lb = &loopbacks[dev];
+	if(waserror()){
+		chanfree(c);
+		nexterror();
+	}
 
+	lb = &loopbacks[dev];
 	qlock(lb);
 	if(waserror()){
 		lb->ref--;
@@ -167,6 +171,8 @@
 	}
 	poperror();
 	qunlock(lb);
+
+	poperror();
 
 	mkqid(&c->qid, QID(0, Qtopdir), 0, QTDIR);
 	c->aux = lb;