summaryrefslogtreecommitdiff
path: root/libutils/ProcessCallStack.cpp
diff options
context:
space:
mode:
authorJames Hawkins <jhawkins@google.com>2016-02-18 14:52:46 -0800
committerJames Hawkins <jhawkins@google.com>2016-02-18 14:52:46 -0800
commit588a2cad7faee54bfb16050d0c7398709f304fea (patch)
tree5e2a3038be92721e92674078f739e5b91efa3d5b /libutils/ProcessCallStack.cpp
parentd3289ac581816861721b81f7100794fad075c497 (diff)
system/core: Cleanup direct calls to opendir by containing in a
std::unique_ptr. Bug: 26643633 Change-Id: Ia3491fdbff086558da694ae949cf08e4c89d0307
Diffstat (limited to 'libutils/ProcessCallStack.cpp')
-rw-r--r--libutils/ProcessCallStack.cpp8
1 files changed, 3 insertions, 5 deletions
diff --git a/libutils/ProcessCallStack.cpp b/libutils/ProcessCallStack.cpp
index cdb586d98..4e87a9875 100644
--- a/libutils/ProcessCallStack.cpp
+++ b/libutils/ProcessCallStack.cpp
@@ -21,6 +21,7 @@
#include <errno.h>
#include <stdio.h>
#include <string.h>
+#include <memory>
#include <utils/Log.h>
#include <utils/Errors.h>
@@ -130,11 +131,10 @@ void ProcessCallStack::clear() {
}
void ProcessCallStack::update() {
- DIR *dp;
struct dirent *ep;
struct dirent entry;
- dp = opendir(PATH_SELF_TASK);
+ std::unique_ptr<DIR, decltype(&closedir)> dp(opendir(PATH_SELF_TASK), closedir);
if (dp == NULL) {
ALOGE("%s: Failed to update the process's call stacks: %s",
__FUNCTION__, strerror(errno));
@@ -159,7 +159,7 @@ void ProcessCallStack::update() {
* - Read every file in directory => get every tid
*/
int code;
- while ((code = readdir_r(dp, &entry, &ep)) == 0 && ep != NULL) {
+ while ((code = readdir_r(dp.get(), &entry, &ep)) == 0 && ep != NULL) {
pid_t tid = -1;
sscanf(ep->d_name, "%d", &tid);
@@ -198,8 +198,6 @@ void ProcessCallStack::update() {
ALOGE("%s: Failed to readdir from %s: %s",
__FUNCTION__, PATH_SELF_TASK, strerror(code));
}
-
- closedir(dp);
}
void ProcessCallStack::log(const char* logtag, android_LogPriority priority,