add a helper function for freeing a device