Christoph Mallon: Remove pointless if (x) before SDL_FreeSurface(x)

This commit is contained in:
Sam Lantinga 2013-08-29 08:29:51 -07:00
parent f79fc33a39
commit 3e2930defe
9 changed files with 51 additions and 123 deletions

View File

@ -571,9 +571,7 @@ SDL_CreateColorCursor(SDL_Surface *surface, int hot_x, int hot_y)
mouse->cursors = cursor;
}
if (temp) {
SDL_FreeSurface(temp);
}
SDL_FreeSurface(temp);
return cursor;
}

View File

@ -1012,10 +1012,8 @@ SDL_SW_SetupYUVDisplay(SDL_SW_YUVTexture * swdata, Uint32 target_format)
break;
}
if (swdata->display) {
SDL_FreeSurface(swdata->display);
swdata->display = NULL;
}
SDL_FreeSurface(swdata->display);
swdata->display = NULL;
return 0;
}
@ -1338,12 +1336,8 @@ SDL_SW_DestroyYUVTexture(SDL_SW_YUVTexture * swdata)
SDL_free(swdata->pixels);
SDL_free(swdata->colortab);
SDL_free(swdata->rgb_2_pix);
if (swdata->stretch) {
SDL_FreeSurface(swdata->stretch);
}
if (swdata->display) {
SDL_FreeSurface(swdata->display);
}
SDL_FreeSurface(swdata->stretch);
SDL_FreeSurface(swdata->display);
SDL_free(swdata);
}
}

View File

@ -398,9 +398,7 @@ SDL_LoadBMP_RW(SDL_RWops * src, int freesrc)
if (src) {
SDL_RWseek(src, fp_offset, RW_SEEK_SET);
}
if (surface) {
SDL_FreeSurface(surface);
}
SDL_FreeSurface(surface);
surface = NULL;
}
if (freesrc && src) {

View File

@ -1432,9 +1432,7 @@ SDL_SetWindowIcon(SDL_Window * window, SDL_Surface * icon)
return;
}
if (window->icon) {
SDL_FreeSurface(window->icon);
}
SDL_FreeSurface(window->icon);
/* Convert the icon into ARGB8888 */
window->icon = SDL_ConvertSurfaceFormat(icon, SDL_PIXELFORMAT_ARGB8888, 0);
@ -2183,9 +2181,7 @@ SDL_DestroyWindow(SDL_Window * window)
/* Free memory associated with the window */
SDL_free(window->title);
if (window->icon) {
SDL_FreeSurface(window->icon);
}
SDL_FreeSurface(window->icon);
SDL_free(window->gamma);
while (window->data) {
SDL_WindowUserData *data = window->data;

View File

@ -237,8 +237,7 @@ DirectFB_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon)
}
return;
error:
if (surface)
SDL_FreeSurface(surface);
SDL_FreeSurface(surface);
SDL_DFB_RELEASE(windata->icon);
return;
}

View File

@ -38,9 +38,7 @@ int SDL_DUMMY_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * forma
/* Free the old framebuffer surface */
surface = (SDL_Surface *) SDL_GetWindowData(window, DUMMY_SURFACE);
if (surface) {
SDL_FreeSurface(surface);
}
SDL_FreeSurface(surface);
/* Create a new one */
SDL_PixelFormatEnumToMasks(surface_format, &bpp, &Rmask, &Gmask, &Bmask, &Amask);
@ -83,9 +81,7 @@ void SDL_DUMMY_DestroyWindowFramebuffer(_THIS, SDL_Window * window)
SDL_Surface *surface;
surface = (SDL_Surface *) SDL_SetWindowData(window, DUMMY_SURFACE, NULL);
if (surface) {
SDL_FreeSurface(surface);
}
SDL_FreeSurface(surface);
}
#endif /* SDL_VIDEO_DRIVER_DUMMY */

View File

@ -190,10 +190,8 @@ int render_testPrimitives (void *arg)
_compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE );
/* Clean up. */
if (referenceSurface != NULL) {
SDL_FreeSurface(referenceSurface);
referenceSurface = NULL;
}
SDL_FreeSurface(referenceSurface);
referenceSurface = NULL;
return TEST_COMPLETED;
}
@ -333,10 +331,8 @@ int render_testPrimitivesBlend (void *arg)
_compare(referenceSurface, ALLOWABLE_ERROR_BLENDED );
/* Clean up. */
if (referenceSurface != NULL) {
SDL_FreeSurface(referenceSurface);
referenceSurface = NULL;
}
SDL_FreeSurface(referenceSurface);
referenceSurface = NULL;
return TEST_COMPLETED;
}
@ -400,10 +396,8 @@ render_testBlit(void *arg)
/* Clean up. */
SDL_DestroyTexture( tface );
if (referenceSurface != NULL) {
SDL_FreeSurface(referenceSurface);
referenceSurface = NULL;
}
SDL_FreeSurface(referenceSurface);
referenceSurface = NULL;
return TEST_COMPLETED;
}
@ -470,10 +464,8 @@ render_testBlitColor (void *arg)
/* Clean up. */
SDL_DestroyTexture( tface );
if (referenceSurface != NULL) {
SDL_FreeSurface(referenceSurface);
referenceSurface = NULL;
}
SDL_FreeSurface(referenceSurface);
referenceSurface = NULL;
return TEST_COMPLETED;
}
@ -543,10 +535,8 @@ render_testBlitAlpha (void *arg)
/* Clean up. */
SDL_DestroyTexture( tface );
if (referenceSurface != NULL) {
SDL_FreeSurface(referenceSurface);
referenceSurface = NULL;
}
SDL_FreeSurface(referenceSurface);
referenceSurface = NULL;
return TEST_COMPLETED;
}
@ -655,37 +645,29 @@ render_testBlitBlend (void *arg)
_testBlitBlendMode( tface, SDL_BLENDMODE_NONE );
referenceSurface = SDLTest_ImageBlitBlendNone();
_compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE );
if (referenceSurface != NULL) {
SDL_FreeSurface(referenceSurface);
referenceSurface = NULL;
}
SDL_FreeSurface(referenceSurface);
referenceSurface = NULL;
/* Test Blend. */
_testBlitBlendMode( tface, SDL_BLENDMODE_BLEND );
referenceSurface = SDLTest_ImageBlitBlend();
_compare(referenceSurface, ALLOWABLE_ERROR_BLENDED );
if (referenceSurface != NULL) {
SDL_FreeSurface(referenceSurface);
referenceSurface = NULL;
}
SDL_FreeSurface(referenceSurface);
referenceSurface = NULL;
/* Test Add. */
_testBlitBlendMode( tface, SDL_BLENDMODE_ADD );
referenceSurface = SDLTest_ImageBlitBlendAdd();
_compare(referenceSurface, ALLOWABLE_ERROR_BLENDED );
if (referenceSurface != NULL) {
SDL_FreeSurface(referenceSurface);
referenceSurface = NULL;
}
SDL_FreeSurface(referenceSurface);
referenceSurface = NULL;
/* Test Mod. */
_testBlitBlendMode( tface, SDL_BLENDMODE_MOD);
referenceSurface = SDLTest_ImageBlitBlendMod();
_compare(referenceSurface, ALLOWABLE_ERROR_BLENDED );
if (referenceSurface != NULL) {
SDL_FreeSurface(referenceSurface);
referenceSurface = NULL;
}
SDL_FreeSurface(referenceSurface);
referenceSurface = NULL;
/* Clear surface. */
_clearScreen();
@ -733,10 +715,8 @@ render_testBlitBlend (void *arg)
/* Check to see if final image matches. */
referenceSurface = SDLTest_ImageBlitBlendAll();
_compare(referenceSurface, ALLOWABLE_ERROR_BLENDED);
if (referenceSurface != NULL) {
SDL_FreeSurface(referenceSurface);
referenceSurface = NULL;
}
SDL_FreeSurface(referenceSurface);
referenceSurface = NULL;
return TEST_COMPLETED;
}
@ -996,9 +976,7 @@ _compare(SDL_Surface *referenceSurface, int allowable_error)
/* Clean up. */
SDL_free(pixels);
if (testSurface != NULL) {
SDL_FreeSurface(testSurface);
}
SDL_FreeSurface(testSurface);
}
/**

View File

@ -63,14 +63,10 @@ _surfaceSetUp(void *arg)
void
_surfaceTearDown(void *arg)
{
if (referenceSurface != NULL) {
SDL_FreeSurface(referenceSurface);
referenceSurface = NULL;
}
if (testSurface != NULL) {
SDL_FreeSurface(testSurface);
testSurface = NULL;
}
SDL_FreeSurface(referenceSurface);
referenceSurface = NULL;
SDL_FreeSurface(testSurface);
testSurface = NULL;
}
/**
@ -193,10 +189,8 @@ void _testBlitBlendMode(int mode)
SDLTest_AssertCheck(checkFailCount4 == 0, "Validate results from calls to SDL_SetSurfaceBlendMode, expected: 0, got: %i", checkFailCount4);
/* Clean up */
if (face != NULL) {
SDL_FreeSurface(face);
face = NULL;
}
SDL_FreeSurface(face);
face = NULL;
}
/* Helper to check that a file exists */
@ -250,14 +244,10 @@ surface_testSaveLoadBitmap(void *arg)
unlink(sampleFilename);
/* Clean up */
if (face != NULL) {
SDL_FreeSurface(face);
face = NULL;
}
if (rface != NULL) {
SDL_FreeSurface(rface);
rface = NULL;
}
return TEST_COMPLETED;
}
@ -294,14 +284,10 @@ surface_testSurfaceConversion(void *arg)
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
/* Clean up. */
if (face != NULL) {
SDL_FreeSurface( face );
face = NULL;
}
if (rface != NULL) {
SDL_FreeSurface( rface );
rface = NULL;
}
SDL_FreeSurface(face);
face = NULL;
SDL_FreeSurface(rface);
rface = NULL;
return TEST_COMPLETED;
}
@ -427,9 +413,7 @@ surface_testBlit(void *arg)
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
/* Clean up. */
if (compareSurface != NULL) {
SDL_FreeSurface( compareSurface );
}
SDL_FreeSurface(compareSurface);
return TEST_COMPLETED;
}
@ -452,9 +436,7 @@ surface_testBlitColorMod(void *arg)
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
/* Clean up. */
if (compareSurface != NULL) {
SDL_FreeSurface( compareSurface );
}
SDL_FreeSurface(compareSurface);
return TEST_COMPLETED;
}
@ -477,9 +459,7 @@ surface_testBlitAlphaMod(void *arg)
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
/* Clean up. */
if (compareSurface != NULL) {
SDL_FreeSurface( compareSurface );
}
SDL_FreeSurface(compareSurface);
return TEST_COMPLETED;
}
@ -503,9 +483,7 @@ surface_testBlitBlendNone(void *arg)
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
/* Clean up. */
if (compareSurface != NULL) {
SDL_FreeSurface( compareSurface );
}
SDL_FreeSurface(compareSurface);
return TEST_COMPLETED;
}
@ -528,9 +506,7 @@ surface_testBlitBlendBlend(void *arg)
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
/* Clean up. */
if (compareSurface != NULL) {
SDL_FreeSurface( compareSurface );
}
SDL_FreeSurface(compareSurface);
return TEST_COMPLETED;
}
@ -553,9 +529,7 @@ surface_testBlitBlendAdd(void *arg)
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
/* Clean up. */
if (compareSurface != NULL) {
SDL_FreeSurface( compareSurface );
}
SDL_FreeSurface(compareSurface);
return TEST_COMPLETED;
}
@ -578,9 +552,7 @@ surface_testBlitBlendMod(void *arg)
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
/* Clean up. */
if (compareSurface != NULL) {
SDL_FreeSurface( compareSurface );
}
SDL_FreeSurface(compareSurface);
return TEST_COMPLETED;
}
@ -603,9 +575,7 @@ surface_testBlitBlendLoop(void *arg) {
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
/* Clean up. */
if (compareSurface != NULL) {
SDL_FreeSurface(compareSurface);
}
SDL_FreeSurface(compareSurface);
return TEST_COMPLETED;

View File

@ -90,8 +90,7 @@ int main(int argc,char** argv)
if(pictures[i].surface == NULL) {
j = 0;
for(j=0;j<num_pictures;j++)
if(pictures[j].surface != NULL)
SDL_FreeSurface(pictures[j].surface);
SDL_FreeSurface(pictures[j].surface);
SDL_free(pictures);
SDL_VideoQuit();
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not load surface from named bitmap file.");