From 4ca17847124b2f8862b1ee46c65f77af702759b4 Mon Sep 17 00:00:00 2001 From: Slawomir Milczarek Date: Mon, 16 Nov 2020 12:12:55 +0100 Subject: [PATCH] Fixed close fd after calling drm ioctl prime fd to handle Signed-off-by: Slawomir Milczarek --- shared/source/os_interface/linux/drm_memory_manager.cpp | 4 ++-- shared/test/unit_test/mocks/linux/mock_drm_memory_manager.h | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/shared/source/os_interface/linux/drm_memory_manager.cpp b/shared/source/os_interface/linux/drm_memory_manager.cpp index 544e678417..a87b39a0b7 100644 --- a/shared/source/os_interface/linux/drm_memory_manager.cpp +++ b/shared/source/os_interface/linux/drm_memory_manager.cpp @@ -572,8 +572,6 @@ GraphicsAllocation *DrmMemoryManager::createGraphicsAllocationFromSharedHandle(o return nullptr; } - closeFunction(openFd.fd); - auto boHandle = openFd.handle; auto bo = findAndReferenceSharedBufferObject(boHandle); @@ -588,6 +586,8 @@ GraphicsAllocation *DrmMemoryManager::createGraphicsAllocationFromSharedHandle(o pushSharedBufferObject(bo); } + closeFunction(handle); + lock.unlock(); auto drmAllocation = new DrmAllocation(properties.rootDeviceIndex, properties.allocationType, bo, reinterpret_cast(bo->gpuAddress), bo->size, diff --git a/shared/test/unit_test/mocks/linux/mock_drm_memory_manager.h b/shared/test/unit_test/mocks/linux/mock_drm_memory_manager.h index 804c6b4ce9..9166ebca4a 100644 --- a/shared/test/unit_test/mocks/linux/mock_drm_memory_manager.h +++ b/shared/test/unit_test/mocks/linux/mock_drm_memory_manager.h @@ -38,6 +38,9 @@ inline int munmapMock(void *addr, size_t length) noexcept { inline off_t lseekMock(int fd, off_t offset, int whence) noexcept { lseekCalledCount++; + if ((fd == closeInputFd) && (closeCalledCount > 0)) { + return 0; + } return lseekReturn; } inline int closeMock(int fd) {