Patch for fixing unsafe device close (issue #1).