Correctly handle dup() failure in Parcel::readNativeHandle am: 1de7966c72
am: 275c9f60f9

* commit '275c9f60f94780bd686eca9750ec41cc1fafa333':
  Correctly handle dup() failure in Parcel::readNativeHandle

Change-Id: I6516dea7eac82d06e1ffd1d269dbb6415fece948
diff --git a/libs/binder/Parcel.cpp b/libs/binder/Parcel.cpp
index 0464e93..c383a2d 100644
--- a/libs/binder/Parcel.cpp
+++ b/libs/binder/Parcel.cpp
@@ -1150,7 +1150,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) {