diff options
author | James Hawkins <jhawkins@google.com> | 2016-02-18 14:52:46 -0800 |
---|---|---|
committer | James Hawkins <jhawkins@google.com> | 2016-02-18 14:52:46 -0800 |
commit | 588a2cad7faee54bfb16050d0c7398709f304fea (patch) | |
tree | 5e2a3038be92721e92674078f739e5b91efa3d5b /fastboot/usb_linux.cpp | |
parent | d3289ac581816861721b81f7100794fad075c497 (diff) |
system/core: Cleanup direct calls to opendir by containing in a
std::unique_ptr.
Bug: 26643633
Change-Id: Ia3491fdbff086558da694ae949cf08e4c89d0307
Diffstat (limited to 'fastboot/usb_linux.cpp')
-rw-r--r-- | fastboot/usb_linux.cpp | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/fastboot/usb_linux.cpp b/fastboot/usb_linux.cpp index 02ffcd978..d4824fb2a 100644 --- a/fastboot/usb_linux.cpp +++ b/fastboot/usb_linux.cpp @@ -145,7 +145,7 @@ static int filter_usb_device(char* sysfs_name, int in, out; unsigned i; unsigned e; - + if (check(ptr, len, USB_DT_DEVICE, USB_DT_DEVICE_SIZE)) return -1; dev = (struct usb_device_descriptor *)ptr; @@ -333,15 +333,14 @@ static std::unique_ptr<usb_handle> find_usb_device(const char* base, ifc_match_f char desc[1024]; int n, in, out, ifc; - DIR *busdir; struct dirent *de; int fd; int writable; - busdir = opendir(base); + std::unique_ptr<DIR, decltype(&closedir)> busdir(opendir(base), closedir); if (busdir == 0) return 0; - while ((de = readdir(busdir)) && (usb == nullptr)) { + while ((de = readdir(busdir.get())) && (usb == nullptr)) { if (badname(de->d_name)) continue; if (!convert_to_devfs_name(de->d_name, devname, sizeof(devname))) { @@ -377,7 +376,6 @@ static std::unique_ptr<usb_handle> find_usb_device(const char* base, ifc_match_f } } } - closedir(busdir); return usb; } |