git: 9front

Download patch

ref: 62d71e551d0bc58c82ff8e06307c6566174dff1c
parent: 080efc4f6a7abe034515b7359f5b575a41234742
author: cinap_lenrek <cinap_lenrek@gmx.de>
date: Tue Aug 27 19:23:29 EDT 2013

devkbd: fix wrong refcount on open error

only decrement refcount when file was successfully opend
on clunk, fix refcount when devopen() errors.

--- a/sys/src/9/pc/devkbd.c
+++ b/sys/src/9/pc/devkbd.c
@@ -339,10 +339,15 @@
 	if(!iseve())
 		error(Eperm);
 	if(c->qid.path == Qscancode){
-		if(incref(&kbd.ref) != 1){
+		if(waserror()){
 			decref(&kbd.ref);
-			error(Einuse);
+			nexterror();
 		}
+		if(incref(&kbd.ref) != 1)
+			error(Einuse);
+		c = devopen(c, omode, kbdtab, nelem(kbdtab), devgen);
+		poperror();
+		return c;
 	}
 	return devopen(c, omode, kbdtab, nelem(kbdtab), devgen);
 }
@@ -350,7 +355,7 @@
 static void
 kbdclose(Chan *c)
 {
-	if(c->qid.path == Qscancode)
+	if((c->flag & COPEN) && c->qid.path == Qscancode)
 		decref(&kbd.ref);
 }
 
--