diff options
author | Jeff Brown <jeffbrown@google.com> | 2011-11-04 20:19:33 -0700 |
---|---|---|
committer | Jeff Brown <jeffbrown@google.com> | 2011-11-07 12:22:39 -0800 |
commit | d341c7178fffc7ad5b57645c2bcf5a395ca95591 (patch) | |
tree | 87cd26544cae0633e8eeb008f43ccdedf813eeb7 /libs/binder | |
parent | be37dde7872a5eeb083cfb62b010536bef65fc6c (diff) | |
download | frameworks_native-d341c7178fffc7ad5b57645c2bcf5a395ca95591.zip frameworks_native-d341c7178fffc7ad5b57645c2bcf5a395ca95591.tar.gz frameworks_native-d341c7178fffc7ad5b57645c2bcf5a395ca95591.tar.bz2 |
Fix possible leak in Parcel::writeDupFileDescriptor.
Also, check the result of dup() just in case we got EMFILE
or something.
Change-Id: I18e627bd84f4c7941813fe1c2bad2cdd9e5afa83
Diffstat (limited to 'libs/binder')
-rw-r--r-- | libs/binder/Parcel.cpp | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/libs/binder/Parcel.cpp b/libs/binder/Parcel.cpp index 26571ce..6cd43aa 100644 --- a/libs/binder/Parcel.cpp +++ b/libs/binder/Parcel.cpp @@ -722,7 +722,15 @@ status_t Parcel::writeFileDescriptor(int fd, bool takeOwnership) status_t Parcel::writeDupFileDescriptor(int fd) { - return writeFileDescriptor(dup(fd), true /*takeOwnership*/); + int dupFd = dup(fd); + if (dupFd < 0) { + return -errno; + } + status_t err = writeFileDescriptor(dupFd, true /*takeOwnership*/); + if (err) { + close(dupFd); + } + return err; } status_t Parcel::writeBlob(size_t len, WritableBlob* outBlob) |