Correctly handle dup() failure in Parcel::readNativeHandle am: 1de7966c72 am: 275c9f60f9 am: 853702ce3d am: 775f2e6dbf
am: 82afbe2258

* commit '82afbe2258c5c5e18ea6e9496d590cff177e67d4':
  Correctly handle dup() failure in Parcel::readNativeHandle

Change-Id: I2c52991c2e6b1c5ef2eebbc4649b36c30dd9120d
diff --git a/libs/binder/Parcel.cpp b/libs/binder/Parcel.cpp
index 87ce5d0..ba7ccfc 100644
--- a/libs/binder/Parcel.cpp
+++ b/libs/binder/Parcel.cpp
@@ -1221,7 +1221,13 @@
 
     for (int i=0 ; err==NO_ERROR && i<numFds ; i++) {
         h->data[i] = dup(readFileDescriptor());
-        if (h->data[i] < 0) err = BAD_VALUE;
+        if (h->data[i] < 0) {
+            for (int j = 0; j < i; j++) {
+                close(h->data[j]);
+            }
+            native_handle_delete(h);
+            return 0;
+        }
     }
     err = read(h->data + numFds, sizeof(int)*numInts);
     if (err != NO_ERROR) {