From 52a84514acca8c2afc7e33c6f3f7d95235cad75e Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Tue, 27 Aug 2013 23:26:30 +0200 Subject: [PATCH] devmouse: fix openmode() handling openmode() can raise error with invalid mode passed, but we already incremented the exclusive mouse refcount at that point! call openmode() early to avoid this. --- sys/src/9/port/devmouse.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sys/src/9/port/devmouse.c b/sys/src/9/port/devmouse.c index c16ed0b60..2f8ffe6e2 100644 --- a/sys/src/9/port/devmouse.c +++ b/sys/src/9/port/devmouse.c @@ -170,6 +170,9 @@ mousestat(Chan *c, uchar *db, int n) static Chan* mouseopen(Chan *c, int omode) { + int mode; + + mode = openmode(omode); switch((ulong)c->qid.path){ case Qdir: if(omode != OREAD) @@ -193,7 +196,7 @@ mouseopen(Chan *c, int omode) default: incref(&mouse); } - c->mode = openmode(omode); + c->mode = mode; c->flag |= COPEN; c->offset = 0; return c;