From cd6670bff328e7f2491c207747a2d49a9b20648a Mon Sep 17 00:00:00 2001 From: Sylvain Becker Date: Fri, 2 Oct 2020 10:48:27 +0200 Subject: [PATCH] SDL_Surface refcount: fix memory leak when blitting between stack'ed surfaces (see bug 5226) --- src/video/SDL_surface.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/video/SDL_surface.c b/src/video/SDL_surface.c index 553946516..3d505cc0f 100644 --- a/src/video/SDL_surface.c +++ b/src/video/SDL_surface.c @@ -1259,6 +1259,7 @@ int SDL_ConvertPixels(int width, int height, SDL_BlitMap src_blitmap, dst_blitmap; SDL_Rect rect; void *nonconst_src = (void *) src; + int ret; /* Check to make sure we are blitting somewhere, so we don't crash */ if (!dst) { @@ -1311,7 +1312,12 @@ int SDL_ConvertPixels(int width, int height, rect.y = 0; rect.w = width; rect.h = height; - return SDL_LowerBlit(&src_surface, &rect, &dst_surface, &rect); + ret = SDL_LowerBlit(&src_surface, &rect, &dst_surface, &rect); + + /* Free blitmap reference, after blitting between stack'ed surfaces */ + SDL_InvalidateMap(src_surface.map); + + return ret; } /*