Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e45abfa0 authored by Mykola Kondratenko's avatar Mykola Kondratenko Committed by Narayan Kamath
Browse files

Alarm: add missing closedir after opendir when searching for RTC

It is mandatory that closedir() is called to deallocate DIR structure
allocated by opendir().

Fix degrade introduced by Google commit 0eb58268.

Change-Id: Ia12154f7f822153b4fc8e6bfb8b2bae17bc45c1a
parent c71c44a5
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -40,6 +40,8 @@
#include <linux/android_alarm.h>
#include <linux/rtc.h>

#include <memory>

namespace android {

static const size_t N_ANDROID_TIMERFDS = ANDROID_ALARM_TYPE_COUNT + 1;
@@ -323,14 +325,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);