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 */