sdl2-compat: SDL_GameControllerAddMappingsFromRW: avoid segfault

From 21c85dc52c7f0ea44b207642839ac26b56e7e779 Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Wed, 4 Jan 2023 14:56:10 +0300
Subject: [PATCH] SDL_GameControllerAddMappingsFromRW: avoid segfault

---
 src/sdl2_compat.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/src/sdl2_compat.c b/src/sdl2_compat.c
index b78cc5c..853a909 100644
--- a/src/sdl2_compat.c
+++ b/src/sdl2_compat.c
@@ -1877,10 +1877,8 @@ SDL_GameControllerAddMappingsFromRW(SDL2_RWops *rwops2, int freerw)
         if (!freerw) {
             SDL3_DestroyRW(rwops3);  /* don't close it because that'll close the SDL2_RWops. */
         }
-    } else {
-        if (freerw) {
-            SDL_RWclose(rwops2);
-        }
+    } else if (freerw && rwops2) {
+        SDL_RWclose(rwops2);
     }
     return retval;
 }