summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunwei Zhang <Jerry.Zhang@amd.com>2018-08-14 11:00:08 +0800
committerChristian König <christian.koenig@amd.com>2018-08-17 12:54:36 +0200
commit3d8b6ea6646e3e86afd83a27014001736cf6fc01 (patch)
tree35c034ad88ea01a8021acfd531d875c9fccc5e92
parentc6493f360e7529c26042b7a5c63725c82de88d8a (diff)
amdgpu: free flink bo in bo import
Fix potential memory leak when handle flink bo in bo import. Free the flink bo after bo import and in error handling. Signed-off-by: Junwei Zhang <Jerry.Zhang@amd.com> Reviewed-by: Christian König <christian.koenig@amd.com>
-rw-r--r--amdgpu/amdgpu_bo.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/amdgpu/amdgpu_bo.c b/amdgpu/amdgpu_bo.c
index 8efd014e..7ea1d0fc 100644
--- a/amdgpu/amdgpu_bo.c
+++ b/amdgpu/amdgpu_bo.c
@@ -255,6 +255,7 @@ int amdgpu_bo_import(amdgpu_device_handle dev,
struct amdgpu_bo_import_result *output)
{
struct drm_gem_open open_arg = {};
+ struct drm_gem_close close_arg = {};
struct amdgpu_bo *bo = NULL;
int r;
int dma_fd;
@@ -342,15 +343,19 @@ int amdgpu_bo_import(amdgpu_device_handle dev,
bo->handle = open_arg.handle;
if (dev->flink_fd != dev->fd) {
+ close_arg.handle = open_arg.handle;
r = drmPrimeHandleToFD(dev->flink_fd, bo->handle, DRM_CLOEXEC, &dma_fd);
if (r) {
free(bo);
+ drmIoctl(dev->flink_fd, DRM_IOCTL_GEM_CLOSE,
+ &close_arg);
pthread_mutex_unlock(&dev->bo_table_mutex);
return r;
}
r = drmPrimeFDToHandle(dev->fd, dma_fd, &bo->handle );
close(dma_fd);
+ drmIoctl(dev->flink_fd, DRM_IOCTL_GEM_CLOSE, &close_arg);
if (r) {
free(bo);