SDL: SDL_ConvertSurface(): add null pointer check

From ac607c108868e63ab617f1848230d37cddeddf20 Mon Sep 17 00:00:00 2001
From: Mingjie Shen <[EMAIL REDACTED]>
Date: Sun, 23 Apr 2023 19:34:57 -0400
Subject: [PATCH] SDL_ConvertSurface(): add null pointer check

Check return values of SDL_CreateSurface()
and SDL_ConvertSurface().
---
 src/video/SDL_surface.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/src/video/SDL_surface.c b/src/video/SDL_surface.c
index 9a67d33892ed..76eacabbbe8c 100644
--- a/src/video/SDL_surface.c
+++ b/src/video/SDL_surface.c
@@ -1293,6 +1293,10 @@ SDL_ConvertSurface(SDL_Surface *surface, const SDL_PixelFormat *format)
 
             /* Create a dummy surface to get the colorkey converted */
             tmp = SDL_CreateSurface(1, 1, surface->format->format);
+            if (tmp == NULL) {
+                SDL_DestroySurface(convert);
+                return NULL;
+            }
 
             /* Share the palette, if any */
             if (surface->format->palette) {
@@ -1305,6 +1309,11 @@ SDL_ConvertSurface(SDL_Surface *surface, const SDL_PixelFormat *format)
 
             /* Convertion of the colorkey */
             tmp2 = SDL_ConvertSurface(tmp, format);
+            if (tmp2 == NULL) {
+                SDL_DestroySurface(tmp);
+                SDL_DestroySurface(convert);
+                return NULL;
+            }
 
             /* Get the converted colorkey */
             SDL_memcpy(&converted_colorkey, tmp2->pixels, tmp2->format->BytesPerPixel);