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

Commit fef48cb6 authored by Yao Chen's avatar Yao Chen
Browse files

Fix StorageManager stack use after scope.

Bug: 75968524
Test: CTS
Change-Id: I2fd81a21452b26d8c9239d7aeddd4907b9618179
parent b09f2b59
Loading
Loading
Loading
Loading
+6 −8
Original line number Diff line number Diff line
@@ -167,8 +167,7 @@ void StorageManager::appendConfigMetricsReport(const ConfigKey& key, ProtoOutput
        return;
    }

    const char* suffix =
            StringPrintf("%d_%lld", key.GetUid(), (long long)key.GetId()).c_str();
    string suffix = StringPrintf("%d_%lld", key.GetUid(), (long long)key.GetId());

    dirent* de;
    while ((de = readdir(dir.get()))) {
@@ -176,9 +175,9 @@ void StorageManager::appendConfigMetricsReport(const ConfigKey& key, ProtoOutput
        if (name[0] == '.') continue;

        size_t nameLen = strlen(name);
        size_t suffixLen = strlen(suffix);
        size_t suffixLen = suffix.length();
        if (suffixLen <= nameLen &&
                strncmp(name + nameLen - suffixLen, suffix, suffixLen) == 0) {
            strncmp(name + nameLen - suffixLen, suffix.c_str(), suffixLen) == 0) {
            int64_t result[3];
            parseFileName(name, result);
            if (result[0] == -1) continue;
@@ -262,8 +261,7 @@ bool StorageManager::hasIdenticalConfig(const ConfigKey& key,
        return false;
    }

    const char* suffix =
            StringPrintf("%d_%lld", key.GetUid(), (long long)key.GetId()).c_str();
    string suffix = StringPrintf("%d_%lld", key.GetUid(), (long long)key.GetId());

    dirent* de;
    while ((de = readdir(dir.get()))) {
@@ -272,10 +270,10 @@ bool StorageManager::hasIdenticalConfig(const ConfigKey& key,
            continue;
        }
        size_t nameLen = strlen(name);
        size_t suffixLen = strlen(suffix);
        size_t suffixLen = suffix.length();
        // There can be at most one file that matches this suffix (config key).
        if (suffixLen <= nameLen &&
                strncmp(name + nameLen - suffixLen, suffix, suffixLen) == 0) {
            strncmp(name + nameLen - suffixLen, suffix.c_str(), suffixLen) == 0) {
            int fd = open(StringPrintf("%s/%s", STATS_SERVICE_DIR, name).c_str(),
                                  O_RDONLY | O_CLOEXEC);
            if (fd != -1) {