From d341c7178fffc7ad5b57645c2bcf5a395ca95591 Mon Sep 17 00:00:00 2001 From: Jeff Brown Date: Fri, 4 Nov 2011 20:19:33 -0700 Subject: Fix possible leak in Parcel::writeDupFileDescriptor. Also, check the result of dup() just in case we got EMFILE or something. Change-Id: I18e627bd84f4c7941813fe1c2bad2cdd9e5afa83 --- libs/binder/Parcel.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'libs/binder/Parcel.cpp') diff --git a/libs/binder/Parcel.cpp b/libs/binder/Parcel.cpp index 26571ce970..6cd43aaf0e 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) -- cgit v1.2.3-59-g8ed1b