From 5fa7b291d426f36e8f05e70435b838c402a92433 Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Fri, 27 Oct 2023 01:30:13 -0400
Subject: [PATCH] wasapi: Fixed memory leak if new audio devices fail to add.
---
src/core/windows/SDL_immdevice.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/core/windows/SDL_immdevice.c b/src/core/windows/SDL_immdevice.c
index 3ed2d5f2dc88..12ce1c5d2e1d 100644
--- a/src/core/windows/SDL_immdevice.c
+++ b/src/core/windows/SDL_immdevice.c
@@ -155,6 +155,10 @@ static SDL_AudioDevice *SDL_IMMDevice_Add(const SDL_bool iscapture, const char *
spec.format = SDL_WaveFormatExToSDLFormat((WAVEFORMATEX *)fmt);
device = SDL_AddAudioDevice(iscapture, devname, &spec, handle);
+ if (!device) {
+ SDL_free(handle->immdevice_id);
+ SDL_free(handle);
+ }
}
return device;