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 /libprocessgroup | |
| parent | d3289ac581816861721b81f7100794fad075c497 (diff) | |
| download | core-588a2cad7faee54bfb16050d0c7398709f304fea.tar.gz core-588a2cad7faee54bfb16050d0c7398709f304fea.tar.bz2 core-588a2cad7faee54bfb16050d0c7398709f304fea.zip | |
system/core: Cleanup direct calls to opendir by containing in a
std::unique_ptr.
Bug: 26643633
Change-Id: Ia3491fdbff086558da694ae949cf08e4c89d0307
Diffstat (limited to 'libprocessgroup')
| -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); } } |
