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

Commit 002f02ea authored by Sandeep Patil's avatar Sandeep Patil
Browse files

meminfo: Fix ProcMemInfo ForEachVmaFromFile



Caused by passing invalid parameters to getline(3) and the test
failure went unnoticed.

Bug: 111694435
Test: libmeminfo_test 1 --gtest_filter=TestProcMemInfo.ForEachVmaFromFileTest
Change-Id: Ideb39604c58f89237b05d2f7c8edb67c5ae65768
Merged-In: Ideb39604c58f89237b05d2f7c8edb67c5ae65768
Signed-off-by: default avatarSandeep Patil <sspatil@google.com>
parent 5424cade
Loading
Loading
Loading
Loading
+5 −0
Original line number Original line Diff line number Diff line
@@ -374,6 +374,9 @@ TEST(TestProcMemInfo, ForEachVmaFromFileTest) {
    auto collect_vmas = [&](const Vma& v) { vmas.push_back(v); };
    auto collect_vmas = [&](const Vma& v) { vmas.push_back(v); };
    ASSERT_TRUE(ForEachVmaFromFile(path, collect_vmas));
    ASSERT_TRUE(ForEachVmaFromFile(path, collect_vmas));


    // We should get a total of 6 vmas
    ASSERT_EQ(vmas.size(), 6);

    // Expect values to be equal to what we have in testdata1/smaps_short
    // Expect values to be equal to what we have in testdata1/smaps_short
    // Check for sizes first
    // Check for sizes first
    ASSERT_EQ(vmas[0].usage.vss, 32768);
    ASSERT_EQ(vmas[0].usage.vss, 32768);
@@ -468,6 +471,8 @@ TEST(TestProcMemInfo, SmapsTest) {
    auto vmas = proc_mem.Smaps(path);
    auto vmas = proc_mem.Smaps(path);


    ASSERT_FALSE(vmas.empty());
    ASSERT_FALSE(vmas.empty());
    // We should get a total of 6 vmas
    ASSERT_EQ(vmas.size(), 6);


    // Expect values to be equal to what we have in testdata1/smaps_short
    // Expect values to be equal to what we have in testdata1/smaps_short
    // Check for sizes first
    // Check for sizes first
+2 −1
Original line number Original line Diff line number Diff line
@@ -338,8 +338,9 @@ bool ForEachVmaFromFile(const std::string& path, const VmaCallback& callback) {
    char* line = nullptr;
    char* line = nullptr;
    bool parsing_vma = false;
    bool parsing_vma = false;
    ssize_t line_len;
    ssize_t line_len;
    size_t line_alloc = 0;
    Vma vma;
    Vma vma;
    while ((line_len = getline(&line, 0, fp.get())) > 0) {
    while ((line_len = getline(&line, &line_alloc, fp.get())) > 0) {
        // Make sure the line buffer terminates like a C string for ReadMapFile
        // Make sure the line buffer terminates like a C string for ReadMapFile
        line[line_len] = '\0';
        line[line_len] = '\0';