From 8df7dbf79106e2b17483d6399e4f43df67b7b9a0 Mon Sep 17 00:00:00 2001 From: Arkadiusz Sarwa Date: Fri, 15 Nov 2019 17:35:24 +0100 Subject: [PATCH] Fix memory leaks in dEQP-VK.api.invariance.random Test dEQP-VK.api.invariance.random contains memory leaks. Change fixes memory leaks. Components: Vulkan VK-GL-CTS Issue: 2110 Affects: dEQP-VK.api.invariance.random Change-Id: I4ccd9d87b69f51da661ca85f10eb347086594aaa --- .../api/vktApiMemoryRequirementInvarianceTests.cpp | 36 +++++++++------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/external/vulkancts/modules/vulkan/api/vktApiMemoryRequirementInvarianceTests.cpp b/external/vulkancts/modules/vulkan/api/vktApiMemoryRequirementInvarianceTests.cpp index 2063159..889c8b3 100644 --- a/external/vulkancts/modules/vulkan/api/vktApiMemoryRequirementInvarianceTests.cpp +++ b/external/vulkancts/modules/vulkan/api/vktApiMemoryRequirementInvarianceTests.cpp @@ -101,14 +101,14 @@ BufferAllocator::~BufferAllocator () void BufferAllocator::allocate (Context& context) { - Allocator& memAlloc = context.getDefaultAllocator(); - IBufferAllocator* allocator = 0; - MemoryRequirement requirement = legalMemoryTypes[m_memoryType]; + Allocator& memAlloc = context.getDefaultAllocator(); + de::MovePtr allocator; + MemoryRequirement requirement = legalMemoryTypes[m_memoryType]; if (m_dedicated) - allocator = new BufferDedicatedAllocation; + allocator = de::MovePtr(new BufferDedicatedAllocation); else - allocator = new BufferSuballocation; + allocator = de::MovePtr(new BufferSuballocation); allocator->createTestBuffer( m_size, @@ -118,8 +118,6 @@ void BufferAllocator::allocate (Context& context) m_buffer, requirement, m_bufferAlloc); - - delete allocator; } void BufferAllocator::deallocate (Context& context) @@ -128,8 +126,7 @@ void BufferAllocator::deallocate (Context& context) const vk::VkDevice& device = context.getDevice(); vk.destroyBuffer(device, m_buffer.disown(), DE_NULL); - vk.freeMemory(device, m_bufferAlloc.get()->getMemory(), (const VkAllocationCallbacks*)DE_NULL); - m_bufferAlloc.release(); + m_bufferAlloc.clear(); } size_t BufferAllocator::getSize (Context &context) @@ -189,14 +186,14 @@ ImageAllocator::~ImageAllocator () void ImageAllocator::allocate (Context& context) { - Allocator& memAlloc = context.getDefaultAllocator(); - IImageAllocator* allocator = 0; - MemoryRequirement requirement = legalMemoryTypes[m_memoryType]; + Allocator& memAlloc = context.getDefaultAllocator(); + de::MovePtr allocator; + MemoryRequirement requirement = legalMemoryTypes[m_memoryType]; if (m_dedicated) - allocator = new ImageDedicatedAllocation; + allocator = de::MovePtr(new ImageDedicatedAllocation); else - allocator = new ImageSuballocation; + allocator = de::MovePtr(new ImageSuballocation); allocator->createTestImage( m_size, @@ -207,8 +204,6 @@ void ImageAllocator::allocate (Context& context) requirement, m_imageAlloc, m_linear ? VK_IMAGE_TILING_LINEAR : VK_IMAGE_TILING_OPTIMAL); - - delete allocator; } void ImageAllocator::deallocate (Context& context) @@ -217,8 +212,7 @@ void ImageAllocator::deallocate (Context& context) const VkDevice& device = context.getDevice(); vk.destroyImage(device, m_image.disown(), DE_NULL); - vk.freeMemory(device, m_imageAlloc.get()->getMemory(), (const VkAllocationCallbacks*)DE_NULL); - m_imageAlloc.release(); + m_imageAlloc.clear(); } size_t ImageAllocator::getSize (Context &context) @@ -256,7 +250,7 @@ InvarianceInstance::~InvarianceInstance (void) tcu::TestStatus InvarianceInstance::iterate (void) { - IObjectAllocator* objs[testCycles]; + de::MovePtr objs[testCycles]; size_t refSizes[testCycles]; unsigned int order[testCycles]; bool success = true; @@ -577,9 +571,9 @@ tcu::TestStatus InvarianceInstance::iterate (void) for (unsigned int i = 0; i < testCycles; i++) { if (deRandom_getBool(&m_random)) - objs[i] = new BufferAllocator(m_random, isDedicatedAllocationSupported, memoryTypes); + objs[i] = de::MovePtr(new BufferAllocator(m_random, isDedicatedAllocationSupported, memoryTypes)); else - objs[i] = new ImageAllocator(m_random, isDedicatedAllocationSupported, linearFormats, optimalFormats, memoryTypes); + objs[i] = de::MovePtr(new ImageAllocator(m_random, isDedicatedAllocationSupported, linearFormats, optimalFormats, memoryTypes)); order[i] = i; } -- 2.7.4