]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - android-sdk/repo-libdce.git/commitdiff
Add check for ownership for file descriptor
authorAmarinder Bindra <a-bindra@ti.com>
Wed, 25 Sep 2013 10:37:33 +0000 (16:07 +0530)
committerGerrit Code Review <gerrit2@git.omapzoom.org>
Fri, 27 Sep 2013 16:20:22 +0000 (11:20 -0500)
Currently, the dce_deinit function deletes the file descriptor(fd) that
it uses for allocation of the buffers even if it has not created it.
This adds a check where it only deletes the fd only when the ownership
of fd is with libdce else it only deletes th device which it uses.
Also, add a check where the dce_set_fd sets the fd only if the drm
device fd is not already set to avoid memory leak.

Change-Id: Ie5e23f06a5d171f2c06f4bebb64b040915e71153
Signed-off-by: Amarinder Bindra <a-bindra@ti.com>
libdce_linux.c

index 39a03e0827a9c9fb82b4f839638e28189f0b7186..2eeb1bd969f72c53fd2985bccb7e614f2f0b0883 100644 (file)
@@ -46,6 +46,7 @@
 #define INVALID_DRM_FD (-1)
 
 int                    OmapDrm_FD  = INVALID_DRM_FD;
+int                    bDrmOpenedByDce = FALSE;
 struct omap_device    *OmapDev     = NULL;
 extern MmRpc_Handle    MmRpcHandle;
 
@@ -60,6 +61,7 @@ void *dce_init(void)
         DEBUG("Open omapdrm device");
         OmapDrm_FD = drmOpen("omapdrm", "platform:omapdrm:00");
         _ASSERT(OmapDrm_FD > 0, DCE_EOMAPDRM_FAIL);
+        bDrmOpenedByDce = TRUE;
     }
     OmapDev = omap_device_new(OmapDrm_FD);
     _ASSERT(OmapDev != NULL, DCE_EOMAPDRM_FAIL);
@@ -72,7 +74,10 @@ void dce_deinit(void *dev)
 {
     omap_device_del(dev);
     dev = NULL;
-    close(OmapDrm_FD);
+    if (bDrmOpenedByDce == TRUE) {
+        close(OmapDrm_FD);
+        bDrmOpenedByDce = FALSE;
+    }
     OmapDrm_FD = INVALID_DRM_FD;
 
     return;
@@ -131,7 +136,12 @@ EXIT:
 /* Incase of X11 or Wayland the fd can be shared to libdce using this call */
 void dce_set_fd(int dce_fd)
 {
-    OmapDrm_FD = dce_fd;
+    if (OmapDrm_FD == INVALID_DRM_FD) {
+        OmapDrm_FD = dce_fd;
+    }
+    else {
+        DEBUG("Cannot set the fd, omapdrm device fd is already set");
+    }
 }
 
 int dce_get_fd(void)