From aad58c622c41b06e52c283b9fc7d5cd777998cf5 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Fri, 29 Sep 2017 07:44:30 -0700 Subject: [PATCH] Fixed bug 3852 - SDL_FreeSurface deallocates surface->map even if the surface is not yet freed Evgeny Kapun Commit 490bb5b49f11 [1], which was a fix for bug #3790, introduced a new bug: now, calling SDL_FreeSurface(surface) deallocates surface->map even if there are other references to the surface. This is bad, because some functions (such as SDL_ConvertSurface) assume that surface->map is not NULL. --- src/video/SDL_surface.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/video/SDL_surface.c b/src/video/SDL_surface.c index 600056fe9..75b699c3a 100644 --- a/src/video/SDL_surface.c +++ b/src/video/SDL_surface.c @@ -1198,10 +1198,8 @@ SDL_FreeSurface(SDL_Surface * surface) if (surface->flags & SDL_DONTFREE) { return; } - if (surface->map != NULL) { - SDL_FreeBlitMap(surface->map); - surface->map = NULL; - } + SDL_InvalidateMap(surface->map); + if (--surface->refcount > 0) { return; }