Commit f1390780ca8561b701222f2748000d8f80bbe99b

Mathieu Eyraud 2022-08-02T15:25:44

Fix use after free when removing Windows audio device

diff --git a/src/audio/wasapi/SDL_wasapi_winrt.cpp b/src/audio/wasapi/SDL_wasapi_winrt.cpp
index a4796f3..235ae7d 100644
--- a/src/audio/wasapi/SDL_wasapi_winrt.cpp
+++ b/src/audio/wasapi/SDL_wasapi_winrt.cpp
@@ -396,8 +396,9 @@ WASAPI_RemoveDevice(const SDL_bool iscapture, LPCWSTR devid)
             SDL_RemoveAudioDevice(iscapture, i->str);
             SDL_free(i->str);
             SDL_free(i);
+        } else {
+            prev = i;
         }
-        prev = i;
     }
 }
 
diff --git a/src/core/windows/SDL_immdevice.c b/src/core/windows/SDL_immdevice.c
index 01658db..0a00a6d 100644
--- a/src/core/windows/SDL_immdevice.c
+++ b/src/core/windows/SDL_immdevice.c
@@ -108,8 +108,9 @@ SDL_IMMDevice_Remove(const SDL_bool iscapture, LPCWSTR devid, SDL_bool useguid)
             SDL_RemoveAudioDevice(iscapture, useguid ? ((void *) i->guid) : ((void *) i->str));
             SDL_free(i->str);
             SDL_free(i);
+        } else {
+            prev = i;
         }
-        prev = i;
     }
 }