Added to code for freeing the allocated devices.