From f27dbb22f0a2d20ebda2d5adbe6ae62165f1903c Mon Sep 17 00:00:00 2001
From: Petar Popovic <[EMAIL REDACTED]>
Date: Tue, 29 Jul 2025 19:51:44 +0200
Subject: [PATCH] Fix two use-after-free warnings
---
src/gpu/vulkan/SDL_gpu_vulkan.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/src/gpu/vulkan/SDL_gpu_vulkan.c b/src/gpu/vulkan/SDL_gpu_vulkan.c
index 759cf5002330a..c76a498289373 100644
--- a/src/gpu/vulkan/SDL_gpu_vulkan.c
+++ b/src/gpu/vulkan/SDL_gpu_vulkan.c
@@ -1250,13 +1250,20 @@ static inline const char *VkErrorMessages(VkResult code)
#undef ERR_TO_STR
}
-#define SET_ERROR_AND_RETURN(fmt, msg, ret) \
+#define SET_ERROR(fmt, msg) \
do { \
if (renderer->debugMode) { \
SDL_LogError(SDL_LOG_CATEGORY_GPU, fmt, msg); \
} \
SDL_SetError((fmt), (msg)); \
- return ret; \
+ } while (0)
+
+#define SET_STRING_ERROR(msg) SET_ERROR("%s", msg)
+
+#define SET_ERROR_AND_RETURN(fmt, msg, ret) \
+ do { \
+ SET_ERROR(fmt, msg); \
+ return ret; \
} while (0)
#define SET_STRING_ERROR_AND_RETURN(msg, ret) SET_ERROR_AND_RETURN("%s", msg, ret)
@@ -11721,9 +11728,10 @@ static SDL_GPUDevice *VULKAN_CreateDevice(bool debugMode, bool preferLowPower, S
renderer->desiredDeviceFeatures.imageCubeArray = VK_TRUE;
if (!VULKAN_INTERNAL_PrepareVulkan(renderer)) {
+ SET_STRING_ERROR("Failed to initialize Vulkan!");
SDL_free(renderer);
SDL_Vulkan_UnloadLibrary();
- SET_STRING_ERROR_AND_RETURN("Failed to initialize Vulkan!", NULL);
+ return NULL;
}
renderer->props = SDL_CreateProperties();
@@ -11828,9 +11836,10 @@ static SDL_GPUDevice *VULKAN_CreateDevice(bool debugMode, bool preferLowPower, S
if (!VULKAN_INTERNAL_CreateLogicalDevice(
renderer)) {
+ SET_STRING_ERROR("Failed to create logical device!");
SDL_free(renderer);
SDL_Vulkan_UnloadLibrary();
- SET_STRING_ERROR_AND_RETURN("Failed to create logical device!", NULL);
+ return NULL;
}
// FIXME: just move this into this function