GDK main function may leak resources
Extracted from https://github.com/libsdl-org/SDL/pull/12676, https://github.com/libsdl-org/SDL/pull/14502#issuecomment-3566921171
Currently, in the GDK implementation of SDL_RunApp(), if GDK_RegisterChangeNotifications() fails, XTaskQueueTerminate(), XTaskQueueCloseHandle() and XGameRuntimeUninitialize() never get called, and argv is never freed. It also appears that the GDK_RegisterChangeNotifications() implementation itself doesn't appear to always clean up resources correctly on failure. It would be good to fix these.
Additionally, the Microsoft docs for XblInitialize() state that it "should have a corresponding call to XblCleanup()", which is currently missing from the GDK SDL_RunApp() and should probably be added for good measure, since it's unclear what the effects of not calling it are.
There is also a !!! FIXME comment about leaking handles despite following the Microsoft docs exactly. But looking at the Microsoft docs for cleaning up a task queue it looks like the example passes a timeout of INFINITE (0xffffffff), while SDL currently passes 0, so perhaps changing that will fix the leak.
Good analysis. Are you able to test and verify a PR to fix these?
I can take a look at it in a few days. I already did most of the brunt work in #12676 but I would need to grab the Windows GDK SDK and try to figure out a way to verify the task queue handle leak fix.