https://github.com/PerlGameDev/SDL/pull/306 https://github.com/PerlGameDev/SDL/issues/305 https://github.com/libsdl-org/sdl12-compat/issues/305 From e9b907c08d9fcce4fccb3084ff38e65cb5c6828b Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 18 Jul 2023 18:00:12 +0100 Subject: [PATCH] Distinguish between owned and borrowed references to a SDL_Surface In many SDL APIs that return a SDL_Surface *, the surface is considered to be owned by the caller, and must be freed by the caller. However, SDL_SetVideoMode and presumably SDL_GetVideoSurface return a pointer to SDL's internal video surface, which will be freed by SDL if necessary, and must not be freed by library users. Incorrectly freeing this surface can lead to a use-after-free crash, manifesting as a test failure in t/core_video.t. See also https://github.com/libsdl-org/sdl12-compat/issues/305 Resolves: https://github.com/PerlGameDev/SDL/issues/305 Signed-off-by: Simon McVittie --- src/Core/Video.xs | 6 ++++-- src/helper.h | 7 ++++--- typemap | 23 +++++++++++++++++++++++ 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/Core/Video.xs b/src/Core/Video.xs index 8efa4b4a..e0d1a679 100644 --- a/src/Core/Video.xs +++ b/src/Core/Video.xs @@ -10,6 +10,8 @@ #include +typedef SDL_Surface SDL_Surface_borrowed; + void _uinta_free(Uint16* av, int len_from_av_len) { if( av != NULL) @@ -56,7 +58,7 @@ See: L