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

Commit 95b71de2 authored by Steven Moreland's avatar Steven Moreland
Browse files

libbinder_ndk: no heap alloc when writing fd

Was doing a heap allocation here out of convenience, but it's not
necessary.

Bug: N/A
Test: atest CtsNdkBinderTestCases
Change-Id: I29ed4eee13c51cbb187b8b767fd55c583f15dcf2
parent f2a15e87
Loading
Loading
Loading
Loading
+4 −9
Original line number Diff line number Diff line
@@ -242,23 +242,18 @@ binder_status_t AParcel_readStrongBinder(const AParcel* parcel, AIBinder** binde
}

binder_status_t AParcel_writeParcelFileDescriptor(AParcel* parcel, int fd) {
    std::unique_ptr<ParcelFileDescriptor> parcelFd;

    if (fd < 0) {
        if (fd != -1) {
            return STATUS_UNKNOWN_ERROR;
        }
        // parcelFd = nullptr
    } else {  // fd >= 0
        parcelFd = std::make_unique<ParcelFileDescriptor>(unique_fd(fd));
        return parcel->get()->writeInt32(0);  // null
    }

    status_t status = parcel->get()->writeNullableParcelable(parcelFd);
    ParcelFileDescriptor parcelFd = ParcelFileDescriptor(unique_fd(fd));
    status_t status = parcel->get()->writeParcelable(parcelFd);

    // ownership is retained by caller
    if (parcelFd != nullptr) {
        (void)parcelFd->release().release();
    }
    (void)parcelFd.release().release();

    return PruneStatusT(status);
}