SDL: video: Fix memory leak when deleting a video display

From 20f1061cc86b07146ba410e551d4994cd430e209 Mon Sep 17 00:00:00 2001
From: Frank Praznik <[EMAIL REDACTED]>
Date: Fri, 21 Jun 2024 13:02:36 -0400
Subject: [PATCH] video: Fix memory leak when deleting a video display

The display deletion code would not free the driver data or name if the display index was the last, or only one, in the list.
---
 src/video/SDL_video.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c
index 74bc77e3c52ac..952b47365aedd 100644
--- a/src/video/SDL_video.c
+++ b/src/video/SDL_video.c
@@ -677,9 +677,9 @@ void SDL_DelVideoDisplay(int index)
 
     SDL_SendDisplayEvent(&_this->displays[index], SDL_DISPLAYEVENT_DISCONNECTED, 0);
 
+    SDL_free(_this->displays[index].driverdata);
+    SDL_free(_this->displays[index].name);
     if (index < (_this->num_displays - 1)) {
-        SDL_free(_this->displays[index].driverdata);
-        SDL_free(_this->displays[index].name);
         SDL_memmove(&_this->displays[index], &_this->displays[index + 1], (_this->num_displays - index - 1) * sizeof(_this->displays[index]));
     }
     --_this->num_displays;