SDL: Fix null-pointer dereference on failing SDL_SYS_CreateProcess

From f6055432c865e36bae3d61fe0b046a8291984245 Mon Sep 17 00:00:00 2001
From: Anonymous Maarten <[EMAIL REDACTED]>
Date: Mon, 16 Sep 2024 16:52:48 +0200
Subject: [PATCH] Fix null-pointer dereference on failing SDL_SYS_CreateProcess

---
 src/process/windows/SDL_windowsprocess.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/process/windows/SDL_windowsprocess.c b/src/process/windows/SDL_windowsprocess.c
index 989711a3152c1..abfacc21b0f50 100644
--- a/src/process/windows/SDL_windowsprocess.c
+++ b/src/process/windows/SDL_windowsprocess.c
@@ -259,6 +259,8 @@ bool SDL_SYS_CreateProcessWithProperties(SDL_Process *process, SDL_PropertiesID
         return false;
     }
     process->internal = data;
+    data->process_information.hProcess = INVALID_HANDLE_VALUE;
+    data->process_information.hThread = INVALID_HANDLE_VALUE;
 
     creation_flags = CREATE_UNICODE_ENVIRONMENT;
 
@@ -533,8 +535,14 @@ void SDL_SYS_DestroyProcess(SDL_Process *process)
     if (io) {
         SDL_CloseIO(io);
     }
-    CloseHandle(data->process_information.hThread);
-    CloseHandle(data->process_information.hProcess);
+    if (data) {
+        if (data->process_information.hThread != INVALID_HANDLE_VALUE) {
+            CloseHandle(data->process_information.hThread);
+        }
+        if (data->process_information.hProcess != INVALID_HANDLE_VALUE) {
+            CloseHandle(data->process_information.hProcess);
+        }
+    }
     SDL_free(data);
 }