copybit: Release fd from intermediate BLIT calls

In certain corner cases copybit would make an intermediate BLIT
call. In these cases the intermediate release fd would be not
be closed.

Change-Id: I031fd5b375a5e9dd8bdcc46c67fc5ccbdfa4dfb7
diff --git a/libcopybit/copybit.cpp b/libcopybit/copybit.cpp
index 65c78f7..25a2cae 100644
--- a/libcopybit/copybit.cpp
+++ b/libcopybit/copybit.cpp
@@ -229,7 +229,12 @@
 /** copy the bits */
 static int msm_copybit(struct copybit_context_t *dev, void const *list)
 {
-    int err = ioctl(dev->mFD, MSMFB_ASYNC_BLIT,
+    int err;
+    if (dev->relFence != -1) {
+        close(dev->relFence);
+        dev->relFence = -1;
+    }
+    err = ioctl(dev->mFD, MSMFB_ASYNC_BLIT,
                     (struct mdp_async_blit_req_list const*)list);
     ALOGE_IF(err<0, "copyBits failed (%s)", strerror(errno));
     if (err == 0) {
@@ -406,7 +411,6 @@
             list->count = 0;
             list->sync.acq_fen_fd_cnt = 0;
             ctx->acqFence[list->sync.acq_fen_fd_cnt++] = acquireFenceFd;
-            ctx->relFence = -1;
         }
     }
     return 0;
@@ -513,9 +517,7 @@
 
             if (++list->count == maxCount) {
                 status = msm_copybit(ctx, list);
-                if (ctx->relFence != -1) {
-                    list->sync.acq_fen_fd_cnt = 0;
-                }
+                list->sync.acq_fen_fd_cnt = 0;
                 list->count = 0;
             }
         }
@@ -523,9 +525,7 @@
             //Before freeing the buffer we need buffer passed through blit call
             if (list->count != 0) {
                 status = msm_copybit(ctx, list);
-                if (ctx->relFence != -1) {
-                    list->sync.acq_fen_fd_cnt = 0;
-                }
+                list->sync.acq_fen_fd_cnt = 0;
                 list->count = 0;
             }
             free_buffer(yv12_handle);