diff options
author | James Hawkins <jhawkins@google.com> | 2016-02-19 17:51:44 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2016-02-19 17:51:44 +0000 |
commit | 0f5d443d0ccc3d3d95604b241cdd23117363f849 (patch) | |
tree | 72368d95171f4aa02c044bf947cd28f0b0c8089d /libprocessgroup/processgroup.cpp | |
parent | a90f7761bf5a73cd6d75fb4b482a1ec08447e1a7 (diff) | |
parent | bd04bb0d297c1a7cd5aabdc258b1829905fb067d (diff) | |
download | core-0f5d443d0ccc3d3d95604b241cdd23117363f849.tar.gz core-0f5d443d0ccc3d3d95604b241cdd23117363f849.tar.bz2 core-0f5d443d0ccc3d3d95604b241cdd23117363f849.zip |
Merge "system/core: Cleanup direct calls to opendir by containing in a std::unique_ptr."
am: bd04bb0d29
* commit 'bd04bb0d297c1a7cd5aabdc258b1829905fb067d':
system/core: Cleanup direct calls to opendir by containing in a std::unique_ptr.
Diffstat (limited to 'libprocessgroup/processgroup.cpp')
-rw-r--r-- | libprocessgroup/processgroup.cpp | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/libprocessgroup/processgroup.cpp b/libprocessgroup/processgroup.cpp index ad0500dab..00a0357f5 100644 --- a/libprocessgroup/processgroup.cpp +++ b/libprocessgroup/processgroup.cpp @@ -28,6 +28,7 @@ #include <string.h> #include <sys/stat.h> #include <sys/types.h> +#include <memory> #include <log/log.h> #include <private/android_filesystem_config.h> @@ -162,11 +163,11 @@ static int removeProcessGroup(uid_t uid, int pid) static void removeUidProcessGroups(const char *uid_path) { - DIR *uid = opendir(uid_path); + std::unique_ptr<DIR, decltype(&closedir)> uid(opendir(uid_path), closedir); if (uid != NULL) { struct dirent cur; struct dirent *dir; - while ((readdir_r(uid, &cur, &dir) == 0) && dir) { + while ((readdir_r(uid.get(), &cur, &dir) == 0) && dir) { char path[PROCESSGROUP_MAX_PATH_LEN]; if (dir->d_type != DT_DIR) { @@ -181,20 +182,19 @@ static void removeUidProcessGroups(const char *uid_path) SLOGV("removing %s\n", path); rmdir(path); } - closedir(uid); } } void removeAllProcessGroups() { SLOGV("removeAllProcessGroups()"); - DIR *root = opendir(PROCESSGROUP_CGROUP_PATH); + std::unique_ptr<DIR, decltype(&closedir)> root(opendir(PROCESSGROUP_CGROUP_PATH), closedir); if (root == NULL) { SLOGE("failed to open %s: %s", PROCESSGROUP_CGROUP_PATH, strerror(errno)); } else { struct dirent cur; struct dirent *dir; - while ((readdir_r(root, &cur, &dir) == 0) && dir) { + while ((readdir_r(root.get(), &cur, &dir) == 0) && dir) { char path[PROCESSGROUP_MAX_PATH_LEN]; if (dir->d_type != DT_DIR) { @@ -209,7 +209,6 @@ void removeAllProcessGroups() SLOGV("removing %s\n", path); rmdir(path); } - closedir(root); } } |