drm_hwcomposer: Do not close duplicate gem handles in nvimporter

When closing gem handles in ReleaseBufferImpl, do not try to close
the same one more than once.

BUG=chrome-os-partner:46443
TEST=Play youtube video, minimize.  Observe no "Failed to close
gem handle" messages in logcat.

Change-Id: I06598f304e3bd167a77f105eb2be86595ada8f4d
Signed-off-by: Isaac Simha <isimha@nvidia.com>
Signed-off-by: Sean Paul <seanpaul@chromium.org>
diff --git a/nvimporter.cpp b/nvimporter.cpp
index de3ed55..71b3b7f 100644
--- a/nvimporter.cpp
+++ b/nvimporter.cpp
@@ -157,10 +157,15 @@
 
     gem_close.handle = bo->gem_handles[i];
     int ret = drmIoctl(drm_->fd(), DRM_IOCTL_GEM_CLOSE, &gem_close);
-    if (ret)
+    if (ret) {
       ALOGE("Failed to close gem handle %d %d", i, ret);
-    else
+    } else {
+      /* Clear any duplicate gem handle as well but don't close again */
+      for(int j = i + 1; j < num_gem_handles; j++)
+        if(bo->gem_handles[j] == bo->gem_handles[i])
+          bo->gem_handles[j] = 0;
       bo->gem_handles[i] = 0;
+    }
   }
 }