Commit 529ed53b16a8e35c81fe3ae3bbf4870067040a22

Sam Lantinga 2014-08-16T23:30:44

Fixed bug 2681 - dereference a NULL pointer dst_fmt in SDL_CreateTextureFromSurface function Nitz In SDL_CreateTextureFromSurface: SDL_PixelFormat *dst_fmt; /* Set up a destination surface for the texture update */ dst_fmt = SDL_AllocFormat(format); temp = SDL_ConvertSurface(surface, dst_fmt, 0); Here is need of NULL check for dst_fmt because there are chances of NULL return from SDL_AllocFormat(format);

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
diff --git a/src/render/SDL_render.c b/src/render/SDL_render.c
index 3aea6bc..1201b0e 100644
--- a/src/render/SDL_render.c
+++ b/src/render/SDL_render.c
@@ -540,6 +540,10 @@ SDL_CreateTextureFromSurface(SDL_Renderer * renderer, SDL_Surface * surface)
 
         /* Set up a destination surface for the texture update */
         dst_fmt = SDL_AllocFormat(format);
+        if (!dst_fmt) {
+           SDL_DestroyTexture(texture);
+           return NULL;
+        }
         temp = SDL_ConvertSurface(surface, dst_fmt, 0);
         SDL_FreeFormat(dst_fmt);
         if (temp) {