git: 9front

Download patch

ref: 82bb1ae8c735f71047bb901ddb77d8fc6a9ade01
parent: 86c008e45d78ba698bafb3265f18794975209712
author: cinap_lenrek <cinap_lenrek@gmx.de>
date: Tue Aug 27 19:57:17 EDT 2013

devproc: properly handle exclusive refcount for /proc/trace

--- a/sys/src/9/port/devproc.c
+++ b/sys/src/9/port/devproc.c
@@ -351,12 +351,12 @@
 			error(Eperm);
 		lock(&tlock);
 		if (waserror()){
+			topens--;
 			unlock(&tlock);
 			nexterror();
 		}
-		if (topens > 0)
+		if (topens++ > 0)
 			error("already open");
-		topens++;
 		if (tevents == nil){
 			tevents = (Traceevent*)malloc(sizeof(Traceevent) * Nevents);
 			if(tevents == nil)
@@ -613,9 +613,9 @@
 }
 
 static void
-procclose(Chan * c)
+procclose(Chan *c)
 {
-	if(QID(c->qid) == Qtrace){
+	if(QID(c->qid) == Qtrace && (c->flag & COPEN) != 0){
 		lock(&tlock);
 		if(topens > 0)
 			topens--;
@@ -623,8 +623,10 @@
 			proctrace = nil;
 		unlock(&tlock);
 	}
-	if(QID(c->qid) == Qns && c->aux != 0)
+	if(QID(c->qid) == Qns && c->aux != 0){
 		free(c->aux);
+		c->aux = 0;
+	}
 }
 
 static void
--