From d66946cee78082635445e8741f8ec3f2f752cc45 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Mon, 3 Nov 2025 10:10:52 -0500 Subject: [PATCH] wasapi: fix memory leak on unlikely failure case. --- src/core/windows/SDL_immdevice.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/core/windows/SDL_immdevice.c b/src/core/windows/SDL_immdevice.c index 93c4afa5d5..cb57ad0abe 100644 --- a/src/core/windows/SDL_immdevice.c +++ b/src/core/windows/SDL_immdevice.c @@ -156,7 +156,7 @@ static SDL_AudioDevice *SDL_IMMDevice_Add(const bool recording, const char *devn SDL_free(handle); return NULL; } - SDL_copyp(&handle->directsound_guid, &dsoundguid); + SDL_copyp(&handle->directsound_guid, dsoundguid); SDL_AudioSpec spec; SDL_zero(spec); @@ -173,10 +173,16 @@ static SDL_AudioDevice *SDL_IMMDevice_Add(const bool recording, const char *devn return NULL; } - SDL_memcpy(&recording_handle->directsound_guid, dsoundguid, sizeof(GUID)); recording_handle->immdevice_id = SDL_wcsdup(devid); + if (!recording_handle->immdevice_id) { + SDL_free(recording_handle); + return NULL; + } - if (!recording_handle->immdevice_id || !SDL_AddAudioDevice(true, devname, &spec, recording_handle)) { + SDL_copyp(&recording_handle->directsound_guid, dsoundguid); + + if (!SDL_AddAudioDevice(true, devname, &spec, recording_handle)) { + SDL_free(recording_handle->immdevice_id); SDL_free(recording_handle); } }