summaryrefslogtreecommitdiffstats
path: root/libprocessgroup/processgroup.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libprocessgroup/processgroup.cpp')
-rw-r--r--libprocessgroup/processgroup.cpp11
1 files changed, 5 insertions, 6 deletions
diff --git a/libprocessgroup/processgroup.cpp b/libprocessgroup/processgroup.cpp
index 5ab957d86..ba97f32f7 100644
--- a/libprocessgroup/processgroup.cpp
+++ b/libprocessgroup/processgroup.cpp
@@ -29,6 +29,7 @@
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
+#include <memory>
#include <log/log.h>
#include <private/android_filesystem_config.h>
@@ -194,11 +195,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) {
@@ -213,7 +214,6 @@ static void removeUidProcessGroups(const char *uid_path)
SLOGV("removing %s\n", path);
rmdir(path);
}
- closedir(uid);
}
}
@@ -221,13 +221,13 @@ void removeAllProcessGroups()
{
SLOGV("removeAllProcessGroups()");
const char *cgroup_root_path = getCgroupRootPath();
- DIR *root = opendir(cgroup_root_path);
+ std::unique_ptr<DIR, decltype(&closedir)> root(opendir(cgroup_root_path), closedir);
if (root == NULL) {
SLOGE("failed to open %s: %s", cgroup_root_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) {
@@ -242,7 +242,6 @@ void removeAllProcessGroups()
SLOGV("removing %s\n", path);
rmdir(path);
}
- closedir(root);
}
}