From 880ab2f10a2d4922d314ff8d016ea078f3c7f019 Mon Sep 17 00:00:00 2001 From: rsc Date: Wed, 15 Feb 2006 23:06:27 +0000 Subject: fixed --- src/cmd/acme/mail/win.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'src/cmd/acme/mail/win.c') diff --git a/src/cmd/acme/mail/win.c b/src/cmd/acme/mail/win.c index e407b0c3..8a3e60a9 100644 --- a/src/cmd/acme/mail/win.c +++ b/src/cmd/acme/mail/win.c @@ -24,9 +24,31 @@ newwindow(void) w->body = nil; w->data = nil; w->cevent = chancreate(sizeof(Event*), 0); + w->ref = 1; return w; } +void +winincref(Window *w) +{ + qlock(&w->lk); + ++w->ref; + qunlock(&w->lk); +} + +void +windecref(Window *w) +{ + qlock(&w->lk); + if(--w->ref > 0){ + qunlock(&w->lk); + return; + } + fsclose(w->event); + chanfree(w->cevent); + free(w); +} + void winsetdump(Window *w, char *dir, char *cmd) { @@ -125,6 +147,7 @@ wingetec(Window *w) w->nbuf = fsread(w->event, w->buf, sizeof w->buf); if(w->nbuf <= 0){ /* probably because window has exited, and only called by wineventproc, so just shut down */ + windecref(w); threadexits(nil); } w->bufp = w->buf; @@ -255,8 +278,6 @@ windel(Window *w, int sure) windormant(w); fsclose(w->ctl); w->ctl = nil; - fsclose(w->event); - w->event = nil; return 1; } -- cgit v1.2.3