Don't leak memory on double init, and don't panic on double fini. Emit

a message when diagnostic.
This commit is contained in:
christos 2002-12-26 12:01:42 +00:00
parent f4d5ba5dbd
commit 1ee98692bb

View File

@ -1,4 +1,4 @@
/* $NetBSD: wsevent.c,v 1.12 2002/11/26 18:49:50 christos Exp $ */
/* $NetBSD: wsevent.c,v 1.13 2002/12/26 12:01:42 christos Exp $ */
/*
* Copyright (c) 1996, 1997 Christopher G. Demetriou. All rights reserved.
@ -79,7 +79,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: wsevent.c,v 1.12 2002/11/26 18:49:50 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: wsevent.c,v 1.13 2002/12/26 12:01:42 christos Exp $");
#include <sys/param.h>
#include <sys/fcntl.h>
@ -100,12 +100,12 @@ void
wsevent_init(struct wseventvar *ev)
{
#ifdef DIAGNOSTIC
if (ev->q != NULL) {
#ifdef DIAGNOSTIC
printf("wsevent_init: already init\n");
#endif
return;
}
#endif
ev->get = ev->put = 0;
ev->q = malloc((u_long)WSEVENT_QSIZE * sizeof(struct wscons_event),
M_DEVBUF, M_WAITOK|M_ZERO);
@ -117,7 +117,12 @@ wsevent_init(struct wseventvar *ev)
void
wsevent_fini(struct wseventvar *ev)
{
if (ev->q == NULL) {
#ifdef DIAGNOSTIC
printf("wsevent_fini: already fini\n");
#endif
return;
}
free(ev->q, M_DEVBUF);
ev->q = NULL;
}