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

Commit 4686c24f authored by Mike Ma's avatar Mike Ma
Browse files

Fix a lambda capture problem in TextDumpsysSection

The [&] capture does not handle smart pointers (unique_ptr, unique_fd
etc) well, which lead to leaked pointers. Fix by explicitly move the
smart pointers.

Bug: 158097879
Test: Build, flash and take an incident report. Verify no crash
Change-Id: I5150aa3dddf9d59c1c9d6d32370370e8cde23946
parent bb9ea4e1
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -477,14 +477,15 @@ status_t TextDumpsysSection::Execute(ReportWriter* writer) const {

    // Run dumping thread
    const uint64_t start = Nanotime();
    std::thread worker([&]() {
    std::thread worker([write_fd = std::move(dumpPipe.writeFd()), service = std::move(service),
                        this]() mutable {
        // Don't crash the service if writing to a closed pipe (may happen if dumping times out)
        signal(SIGPIPE, sigpipe_handler);
        status_t err = service->dump(dumpPipe.writeFd().get(), mArgs);
        status_t err = service->dump(write_fd.get(), this->mArgs);
        if (err != OK) {
            ALOGW("[%s] dump thread failed. Error: %s", this->name.string(), strerror(-err));
        }
        dumpPipe.writeFd().reset();
        write_fd.reset();
    });

    // Collect dump content