Skip to content

Commit f27dbb2

Browse files
Sackzementslouken
authored andcommitted
Fix two use-after-free warnings
1 parent 774c0b3 commit f27dbb2

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/gpu/vulkan/SDL_gpu_vulkan.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,13 +1250,20 @@ static inline const char *VkErrorMessages(VkResult code)
12501250
#undef ERR_TO_STR
12511251
}
12521252

1253-
#define SET_ERROR_AND_RETURN(fmt, msg, ret) \
1253+
#define SET_ERROR(fmt, msg) \
12541254
do { \
12551255
if (renderer->debugMode) { \
12561256
SDL_LogError(SDL_LOG_CATEGORY_GPU, fmt, msg); \
12571257
} \
12581258
SDL_SetError((fmt), (msg)); \
1259-
return ret; \
1259+
} while (0)
1260+
1261+
#define SET_STRING_ERROR(msg) SET_ERROR("%s", msg)
1262+
1263+
#define SET_ERROR_AND_RETURN(fmt, msg, ret) \
1264+
do { \
1265+
SET_ERROR(fmt, msg); \
1266+
return ret; \
12601267
} while (0)
12611268

12621269
#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
1172111728
renderer->desiredDeviceFeatures.imageCubeArray = VK_TRUE;
1172211729

1172311730
if (!VULKAN_INTERNAL_PrepareVulkan(renderer)) {
11731+
SET_STRING_ERROR("Failed to initialize Vulkan!");
1172411732
SDL_free(renderer);
1172511733
SDL_Vulkan_UnloadLibrary();
11726-
SET_STRING_ERROR_AND_RETURN("Failed to initialize Vulkan!", NULL);
11734+
return NULL;
1172711735
}
1172811736

1172911737
renderer->props = SDL_CreateProperties();
@@ -11828,9 +11836,10 @@ static SDL_GPUDevice *VULKAN_CreateDevice(bool debugMode, bool preferLowPower, S
1182811836

1182911837
if (!VULKAN_INTERNAL_CreateLogicalDevice(
1183011838
renderer)) {
11839+
SET_STRING_ERROR("Failed to create logical device!");
1183111840
SDL_free(renderer);
1183211841
SDL_Vulkan_UnloadLibrary();
11833-
SET_STRING_ERROR_AND_RETURN("Failed to create logical device!", NULL);
11842+
return NULL;
1183411843
}
1183511844

1183611845
// FIXME: just move this into this function

0 commit comments

Comments
 (0)