Don't allocate memory if we're just going to fail when checking parameters.
authorRyan C. Gordon <icculus@icculus.org>
Sat, 20 Jul 2013 21:19:20 -0400
changeset 7487 a4e43eb67e79
parent 7486 c074c0b23916
child 7488 a74f1f664047
Don't allocate memory if we're just going to fail when checking parameters.
src/render/SDL_yuv_sw.c
--- a/src/render/SDL_yuv_sw.c	Sat Jul 20 21:10:05 2013 -0400
+++ b/src/render/SDL_yuv_sw.c	Sat Jul 20 21:19:20 2013 -0400
@@ -1029,12 +1029,6 @@
     int i;
     int CR, CB;
 
-    swdata = (SDL_SW_YUVTexture *) SDL_calloc(1, sizeof(*swdata));
-    if (!swdata) {
-        SDL_OutOfMemory();
-        return NULL;
-    }
-
     switch (format) {
     case SDL_PIXELFORMAT_YV12:
     case SDL_PIXELFORMAT_IYUV:
@@ -1043,11 +1037,16 @@
     case SDL_PIXELFORMAT_YVYU:
         break;
     default:
-        SDL_SW_DestroyYUVTexture(swdata);
         SDL_SetError("Unsupported YUV format");
         return NULL;
     }
 
+    swdata = (SDL_SW_YUVTexture *) SDL_calloc(1, sizeof(*swdata));
+    if (!swdata) {
+        SDL_OutOfMemory();
+        return NULL;
+    }
+
     swdata->format = format;
     swdata->target_format = SDL_PIXELFORMAT_UNKNOWN;
     swdata->w = w;
@@ -1095,7 +1094,7 @@
         swdata->planes[0] = swdata->pixels;
         break;
     default:
-        /* We should never get here (caught above) */
+        SDL_assert(0 && "We should never get here (caught above)");
         break;
     }