Skip to content

Commit

Permalink
Christoph Mallon: Remove pointless if (x) before SDL_FreeSurface(x)
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Aug 29, 2013
1 parent f79fc33 commit 3e2930d
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 123 deletions.
4 changes: 1 addition & 3 deletions src/events/SDL_mouse.c
Expand Up @@ -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;
}
Expand Down
14 changes: 4 additions & 10 deletions src/render/SDL_yuv_sw.c
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/video/SDL_bmp.c
Expand Up @@ -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) {
Expand Down
8 changes: 2 additions & 6 deletions src/video/SDL_video.c
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions src/video/directfb/SDL_DirectFB_window.c
Expand Up @@ -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;
}
Expand Down
8 changes: 2 additions & 6 deletions src/video/dummy/SDL_nullframebuffer.c
Expand Up @@ -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);
Expand Down Expand Up @@ -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 */
Expand Down
64 changes: 21 additions & 43 deletions test/testautomation_render.c
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}

/**
Expand Down
66 changes: 18 additions & 48 deletions test/testautomation_surface.c
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;

Expand Down

0 comments on commit 3e2930d

Please sign in to comment.