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

Commit d98f8aff authored by Jeff Brown's avatar Jeff Brown Committed by Android (Google) Code Review
Browse files

Merge "Fix dangling pointer when device closed just after opening." into honeycomb-mr1

parents f40e638e 8e9d4431
Loading
Loading
Loading
Loading
+28 −2
Original line number Diff line number Diff line
@@ -1074,8 +1074,34 @@ int EventHub::closeDeviceAtIndexLocked(int index) {
    mDevices.removeAt(index);
    device->close();

    // Unlink for opening devices list if it is present.
    Device* pred = NULL;
    bool found = false;
    for (Device* entry = mOpeningDevices; entry != NULL; ) {
        if (entry == device) {
            found = true;
            break;
        }
        pred = entry;
        entry = entry->next;
    }
    if (found) {
        // Unlink the device from the opening devices list then delete it.
        // We don't need to tell the client that the device was closed because
        // it does not even know it was opened in the first place.
        LOGI("Device %s was immediately closed after opening.", device->path.string());
        if (pred) {
            pred->next = device->next;
        } else {
            mOpeningDevices = device->next;
        }
        delete device;
    } else {
        // Link into closing devices list.
        // The device will be deleted later after we have informed the client.
        device->next = mClosingDevices;
        mClosingDevices = device;
    }
    return 0;
}