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.

(cherry picked from commit 20f1061cc8)
This commit is contained in:
Frank Praznik 2024-06-21 13:02:36 -04:00
parent 31f77182d0
commit 0f5752b0fc
No known key found for this signature in database
1 changed files with 2 additions and 2 deletions

View File

@ -672,9 +672,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;