Fix leakage of Gem handle on tbm_bcm_bo_import_fd() 10/122110/1
authorMun, Gwan-gyeong <kk.moon@samsung.com>
Thu, 30 Mar 2017 07:45:21 +0000 (16:45 +0900)
committerMun, Gwan-gyeong <kk.moon@samsung.com>
Thu, 30 Mar 2017 07:45:21 +0000 (16:45 +0900)
tbm_bcm_bo_import_fd() calls DRM_IOCTL_GEM_OPEN for getting of buffer size.
but previous implementation does not call DRM_IOCTL_GEM_CLOSE for this handle.
it causes leakeage of gem memory. this patch fixes it.

Change-Id: I0bcb1bd5d5373116088b45aca8a49e2efc357e30
Signed-off-by: Mun, Gwan-gyeong <kk.moon@samsung.com>
src/tbm_bufmgr_vc4.c

index 6ef2ef8..7d00d01 100644 (file)
@@ -1234,7 +1234,6 @@ tbm_vc4_bo_import_fd(tbm_bo bo, tbm_fd key)
        }
 
        unsigned int real_size = -1;
-       //struct drm_vc4_gem_info info = {0, };
 
        /* Determine size of bo.  The fd-to-handle ioctl really should
         * return the size, but it doesn't.  If we have kernel 3.12 or
@@ -1244,16 +1243,6 @@ tbm_vc4_bo_import_fd(tbm_bo bo, tbm_fd key)
         */
        real_size = lseek(key, 0, SEEK_END);
 
-       /*info.handle = gem;
-       if (drmCommandWriteRead(bufmgr_vc4->fd,
-                               DRM_VC4_GEM_GET,
-                               &info,
-                               sizeof(struct drm_vc4_gem_info))) {
-               TBM_VC4_ERROR("bo:%p Cannot get gem info from gem:%d, fd:%d (%s)\n",
-                              bo, gem, key, strerror(errno));
-               return 0;
-       }*/
-
        struct drm_gem_open open_arg = {0, };
 
        open_arg.name = name;
@@ -1262,6 +1251,15 @@ tbm_vc4_bo_import_fd(tbm_bo bo, tbm_fd key)
                return 0;
        }
 
+       struct drm_gem_close close_arg = {0, };
+       memset(&arg, 0, sizeof(close_arg));
+       close_arg.handle = open_arg.handle;
+       if (drmIoctl(bufmgr_vc4->fd, DRM_IOCTL_GEM_CLOSE, &close_arg)) {
+               TBM_VC4_ERROR("Cannot close gem_handle (%d)\n", open_arg.handle,
+                             strerror(errno));
+               return 0;
+       }
+
        if (real_size == -1)
                real_size = open_arg.size;