adb: set O_CLOEXEC on lots of file descriptors
Too many leaking FDs.
Fixes bug: https://code.google.com/p/android/issues/detail?id=65857
(and more)
Change-Id: I67d8683244e54288a8105f6f65ee40abe2378d7e
diff --git a/usb_linux.c b/usb_linux.c
index 8ff753e..f16bdd0 100644
--- a/usb_linux.c
+++ b/usb_linux.c
@@ -170,7 +170,7 @@
}
// DBGX("[ scanning %s ]\n", devname);
- if((fd = unix_open(devname, O_RDONLY)) < 0) {
+ if((fd = unix_open(devname, O_RDONLY | O_CLOEXEC)) < 0) {
continue;
}
@@ -597,10 +597,10 @@
usb->mark = 1;
usb->reaper_thread = 0;
- usb->desc = unix_open(usb->fname, O_RDWR);
+ usb->desc = unix_open(usb->fname, O_RDWR | O_CLOEXEC);
if(usb->desc < 0) {
/* if we fail, see if have read-only access */
- usb->desc = unix_open(usb->fname, O_RDONLY);
+ usb->desc = unix_open(usb->fname, O_RDONLY | O_CLOEXEC);
if(usb->desc < 0) goto fail;
usb->writeable = 0;
D("[ usb open read-only %s fd = %d]\n", usb->fname, usb->desc);