diff options
-rw-r--r-- | services/core/jni/com_android_server_AlarmManagerService.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/services/core/jni/com_android_server_AlarmManagerService.cpp b/services/core/jni/com_android_server_AlarmManagerService.cpp index 80b8923..0352461 100644 --- a/services/core/jni/com_android_server_AlarmManagerService.cpp +++ b/services/core/jni/com_android_server_AlarmManagerService.cpp @@ -40,6 +40,8 @@ #include <linux/android_alarm.h> #include <linux/rtc.h> +#include <memory> + #if HAVE_QC_TIME_SERVICES extern "C" { #include <private/time_genoff.h> @@ -380,14 +382,14 @@ static bool rtc_is_hctosys(unsigned int rtc_id) static int wall_clock_rtc() { - DIR *dir = opendir(rtc_sysfs); - if (!dir) { + std::unique_ptr<DIR, int(*)(DIR*)> dir(opendir(rtc_sysfs), closedir); + if (!dir.get()) { ALOGE("failed to open %s: %s", rtc_sysfs, strerror(errno)); return -1; } struct dirent *dirent; - while (errno = 0, dirent = readdir(dir)) { + while (errno = 0, dirent = readdir(dir.get())) { unsigned int rtc_id; int matched = sscanf(dirent->d_name, "rtc%u", &rtc_id); |