Each opendevice() must eventually be matched by a call to closedevice(). When the last close is performed, the device will deallocate all resources and buffers. All IORequests must be complete before closedevice(). abort any pending requests with abortio(). if (!(CheckIO(SerialIO))) { AbortIO((struct IORequest *)SerialIO); /* Ask device to abort */ } /* request, if pending */ WaitIO((struct IORequest *)SerialIO); /* Wait for abort, then */ CloseDevice((struct IORequest *)SerialIO); /* clean up */