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

Commit 5b4015d9 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
Signed-off-by: default avatarSandeep Patil <sspatil@google.com>
parent c7994e8a
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -374,6 +374,9 @@ TEST(TestProcMemInfo, ForEachVmaFromFileTest) {
    auto collect_vmas = [&](const Vma& v) { vmas.push_back(v); };
    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
    // Check for sizes first
    ASSERT_EQ(vmas[0].usage.vss, 32768);
@@ -468,6 +471,8 @@ TEST(TestProcMemInfo, SmapsTest) {
    auto vmas = proc_mem.Smaps(path);

    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
    // Check for sizes first
+2 −1
Original line number Diff line number Diff line
@@ -338,8 +338,9 @@ bool ForEachVmaFromFile(const std::string& path, const VmaCallback& callback) {
    char* line = nullptr;
    bool parsing_vma = false;
    ssize_t line_len;
    size_t line_alloc = 0;
    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
        line[line_len] = '\0';