[plasma/kwin] src/vulkan: vulkan: drop the graphics buffer when texture import fails

Xaver Hugl <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit ca0c0d7f1fd52b6c6d5cdb092ce8a8c9a55c8ed7 by Xaver Hugl, on behalf of zhang shoucheng.
Committed on 10/08/2026 at 11:34.
Pushed by zamundaaa into branch 'master'.

vulkan: drop the graphics buffer when texture import fails

When importBuffer() fails, the allocated GraphicsBuffer was never
dropped, leaking the buffer and its underlying resources. Drop the
buffer before returning in both VulkanSwapchain::acquire() and
VulkanSwapchain::create().

M  +2    -0    src/vulkan/vulkan_swapchain.cpp

https://invent.kde.org/plasma/kwin/-/commit/ca0c0d7f1fd52b6c6d5cdb092ce8a8c9a55c8ed7

diff --git a/src/vulkan/vulkan_swapchain.cpp b/src/vulkan/vulkan_swapchain.cpp
index fe3dcb62520..58e8493cb5e 100644
--- a/src/vulkan/vulkan_swapchain.cpp
+++ b/src/vulkan/vulkan_swapchain.cpp
@@ -110,6 +110,7 @@ std::shared_ptr<VulkanSwapchainSlot> VulkanSwapchain::acquire()
 
     auto texture = m_device->importBuffer(buffer, VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT);
     if (!texture) {
+        buffer->drop();
         return nullptr;
     }
     auto slot = std::make_shared<VulkanSwapchainSlot>(buffer, std::move(texture));
@@ -145,6 +146,7 @@ std::unique_ptr<VulkanSwapchain> VulkanSwapchain::create(VulkanDevice *device, G
     }
     auto texture = device->importBuffer(buffer, VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT);
     if (!texture) {
+        buffer->drop();
         return nullptr;
     }
     options.modifiers = {buffer->dmabufAttributes()->modifier};
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.