diff options
| author | 2011-11-04 19:01:44 -0700 | |
|---|---|---|
| committer | 2011-11-04 22:16:39 -0700 | |
| commit | 829a6f208cbdcc9eecaa59d086b27b413e3227ee (patch) | |
| tree | a456eff0c2125901510047e529829607ddf56080 /libs/binder/Parcel.cpp | |
| parent | 6d25e3400cee4ca6965a9fd22222a8389c08380c (diff) | |
Fix a leak in Parcel::writeBlob.
Was mistakenly assuming that Parcel::writeFileDescriptor took
ownership of the fd that was passed in. It does not!
Added some comments and a default parameter to allow the caller
to specify whether it wishes the Parcel to take ownership.
Bug: 5563374
Change-Id: I5a12f51d582bf246ce90133cce7690bb9bca93f6
Diffstat (limited to 'libs/binder/Parcel.cpp')
| -rw-r--r-- | libs/binder/Parcel.cpp | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/libs/binder/Parcel.cpp b/libs/binder/Parcel.cpp index c7180cee03cd..6b4c1a61e4c9 100644 --- a/libs/binder/Parcel.cpp +++ b/libs/binder/Parcel.cpp @@ -710,24 +710,19 @@ status_t Parcel::writeNativeHandle(const native_handle* handle) return err; } -status_t Parcel::writeFileDescriptor(int fd) +status_t Parcel::writeFileDescriptor(int fd, bool takeOwnership) { flat_binder_object obj; obj.type = BINDER_TYPE_FD; obj.flags = 0x7f | FLAT_BINDER_FLAG_ACCEPTS_FDS; obj.handle = fd; - obj.cookie = (void*)0; + obj.cookie = (void*) (takeOwnership ? 1 : 0); return writeObject(obj, true); } status_t Parcel::writeDupFileDescriptor(int fd) { - flat_binder_object obj; - obj.type = BINDER_TYPE_FD; - obj.flags = 0x7f | FLAT_BINDER_FLAG_ACCEPTS_FDS; - obj.handle = dup(fd); - obj.cookie = (void*)1; - return writeObject(obj, true); + return writeFileDescriptor(dup(fd), true /*takeOwnership*/); } status_t Parcel::writeBlob(size_t len, WritableBlob* outBlob) @@ -764,7 +759,7 @@ status_t Parcel::writeBlob(size_t len, WritableBlob* outBlob) } else { status = writeInt32(1); if (!status) { - status = writeFileDescriptor(fd); + status = writeFileDescriptor(fd, true /*takeOwnership*/); if (!status) { outBlob->init(true /*mapped*/, ptr, len); return NO_ERROR; |