git: 9front

Download patch

ref: 4751d0f9d7d055dcf821e3a4879e9c9de4a58a29
parent: 0aefe37ed56172da2bd21c10acd930f7cb968288
author: cinap_lenrek <cinap_lenrek@centraldogma>
date: Fri Sep 2 10:12:39 EDT 2011

chan: use chanpath() in chan DBG, do more checking in cclose and cclone

--- a/sys/src/9/port/chan.c
+++ b/sys/src/9/port/chan.c
@@ -472,10 +472,10 @@
 void
 cclose(Chan *c)
 {
-	if(c->flag&CFREE)
+	if(c == nil || c->ref < 1 || c->flag&CFREE)
 		panic("cclose %#p", getcallerpc(&c));
 
-	DBG("cclose %p name=%s ref=%ld\n", c, c->path->s, c->ref);
+	DBG("cclose %p name=%s ref=%ld\n", c, chanpath(c), c->ref);
 	if(decref(c))
 		return;
 
@@ -503,10 +503,10 @@
 void
 ccloseq(Chan *c)
 {
-	if(c->flag&CFREE)
-		panic("cclose %#p", getcallerpc(&c));
+	if(c == nil || c->ref < 1 || c->flag&CFREE)
+		panic("ccloseq %#p", getcallerpc(&c));
 
-	DBG("ccloseq %p name=%s ref=%ld\n", c, c->path->s, c->ref);
+	DBG("ccloseq %p name=%s ref=%ld\n", c, chanpath(c), c->ref);
 
 	if(decref(c))
 		return;
@@ -822,6 +822,8 @@
 	Chan *nc;
 	Walkqid *wq;
 
+	if(c == nil || c->ref < 1 || c->flag&CFREE)
+		panic("cclone: %#p", getcallerpc(&c));
 	wq = devtab[c->type]->walk(c, nil, nil, 0);
 	if(wq == nil)
 		error("clone failed");
--