File tree Expand file tree Collapse file tree 2 files changed +6
-10
lines changed
Expand file tree Collapse file tree 2 files changed +6
-10
lines changed Original file line number Diff line number Diff line change @@ -110,7 +110,8 @@ class Parcel
110110
111111 // Place a file descriptor into the parcel. The given fd must remain
112112 // valid for the lifetime of the parcel.
113- status_t writeFileDescriptor (int fd);
113+ // The Parcel does not take ownership of the given fd unless you ask it to.
114+ status_t writeFileDescriptor (int fd, bool takeOwnership = false );
114115
115116 // Place a file descriptor into the parcel. A dup of the fd is made, which
116117 // will be closed once the parcel is destroyed.
Original file line number Diff line number Diff line change @@ -710,24 +710,19 @@ status_t Parcel::writeNativeHandle(const native_handle* handle)
710710 return err;
711711}
712712
713- status_t Parcel::writeFileDescriptor (int fd)
713+ status_t Parcel::writeFileDescriptor (int fd, bool takeOwnership )
714714{
715715 flat_binder_object obj;
716716 obj.type = BINDER_TYPE_FD;
717717 obj.flags = 0x7f | FLAT_BINDER_FLAG_ACCEPTS_FDS;
718718 obj.handle = fd;
719- obj.cookie = (void *)0 ;
719+ obj.cookie = (void *) (takeOwnership ? 1 : 0 ) ;
720720 return writeObject (obj, true );
721721}
722722
723723status_t Parcel::writeDupFileDescriptor (int fd)
724724{
725- flat_binder_object obj;
726- obj.type = BINDER_TYPE_FD;
727- obj.flags = 0x7f | FLAT_BINDER_FLAG_ACCEPTS_FDS;
728- obj.handle = dup (fd);
729- obj.cookie = (void *)1 ;
730- return writeObject (obj, true );
725+ return writeFileDescriptor (dup (fd), true /* takeOwnership*/ );
731726}
732727
733728status_t Parcel::writeBlob (size_t len, WritableBlob* outBlob)
@@ -764,7 +759,7 @@ status_t Parcel::writeBlob(size_t len, WritableBlob* outBlob)
764759 } else {
765760 status = writeInt32 (1 );
766761 if (!status) {
767- status = writeFileDescriptor (fd);
762+ status = writeFileDescriptor (fd, true /* takeOwnership */ );
768763 if (!status) {
769764 outBlob->init (true /* mapped*/ , ptr, len);
770765 return NO_ERROR;
You can’t perform that action at this time.
0 commit comments