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

Commit 5ee058d7 authored by David Anderson's avatar David Anderson Committed by Gerrit Code Review
Browse files

Merge "fastbootd: Fix transport ownership."

parents 5efd2abe 03de645a
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -88,7 +88,9 @@ void fb_init(fastboot::FastBootDriver& fbi) {
}

void fb_reinit(Transport* transport) {
    fb->set_transport(transport);
    if (Transport* old_transport = fb->set_transport(transport)) {
        delete old_transport;
    }
}

const std::string fb_get_error() {
@@ -392,6 +394,6 @@ bool fb_reboot_to_userspace() {
    }
    fprintf(stderr, "OKAY\n");

    fb->set_transport(nullptr);
    fb_reinit(nullptr);
    return true;
}
+4 −0
Original line number Diff line number Diff line
@@ -1847,6 +1847,10 @@ int FastBootTool::Main(int argc, char* argv[]) {

    int status = fb_execute_queue() ? EXIT_FAILURE : EXIT_SUCCESS;
    fprintf(stderr, "Finished. Total time: %.3fs\n", (now() - start));

    if (Transport* old_transport = fb.set_transport(nullptr)) {
        delete old_transport;
    }
    return status;
}

+3 −7
Original line number Diff line number Diff line
@@ -58,7 +58,6 @@ FastBootDriver::FastBootDriver(Transport* transport, std::function<void(std::str
}

FastBootDriver::~FastBootDriver() {
    set_transport(nullptr);
}

RetCode FastBootDriver::Boot(std::string* response, std::vector<std::string>* info) {
@@ -537,12 +536,9 @@ int FastBootDriver::SparseWriteCallback(std::vector<char>& tpbuf, const char* da
    return 0;
}

void FastBootDriver::set_transport(Transport* transport) {
    if (transport_) {
        transport_->Close();
        delete transport_;
    }
    transport_ = transport;
Transport* FastBootDriver::set_transport(Transport* transport) {
    std::swap(transport_, transport);
    return transport;
}

}  // End namespace fastboot
+2 −2
Original line number Diff line number Diff line
@@ -109,8 +109,8 @@ class FastBootDriver {
    std::string Error();
    RetCode WaitForDisconnect();

    // Note: changing the transport will close and delete the existing one.
    void set_transport(Transport* transport);
    // Note: set_transport will return the previous transport.
    Transport* set_transport(Transport* transport);
    Transport* transport() const { return transport_; }

    // This is temporarily public for engine.cpp
+0 −3
Original line number Diff line number Diff line
@@ -133,7 +133,6 @@ void FastBootTest::TearDown() {
    fb.reset();

    if (transport) {
        transport->Close();
        transport.reset();
    }

@@ -188,7 +187,6 @@ void FastBootTest::SetLockState(bool unlock, bool assert_change) {
        ASSERT_EQ(fb->RawCommand("flashing " + cmd, &resp), SUCCESS)
                << "Attempting to change locked state, but 'flashing" + cmd + "' command failed";
        fb.reset();
        transport->Close();
        transport.reset();
        printf("PLEASE RESPOND TO PROMPT FOR '%sing' BOOTLOADER ON DEVICE\n", cmd.c_str());
        while (UsbStillAvailible())
@@ -249,7 +247,6 @@ void Fuzz::TearDown() {
    }

    if (transport) {
        transport->Close();
        transport.reset();
    }

Loading