Christoph Mallon: Remove pointless if (x) before SDL_FreeSurface(x)
authorSam Lantinga <slouken@libsdl.org>
Thu, 29 Aug 2013 08:29:51 -0700
changeset 7720f9a649383362
parent 7719 31b5f9ff36ca
child 7721 bdf8c2c84e14
Christoph Mallon: Remove pointless if (x) before SDL_FreeSurface(x)
src/events/SDL_mouse.c
src/render/SDL_yuv_sw.c
src/video/SDL_bmp.c
src/video/SDL_video.c
src/video/directfb/SDL_DirectFB_window.c
src/video/dummy/SDL_nullframebuffer.c
test/testautomation_render.c
test/testautomation_surface.c
test/testshape.c
     1.1 --- a/src/events/SDL_mouse.c	Thu Aug 29 08:29:21 2013 -0700
     1.2 +++ b/src/events/SDL_mouse.c	Thu Aug 29 08:29:51 2013 -0700
     1.3 @@ -571,9 +571,7 @@
     1.4          mouse->cursors = cursor;
     1.5      }
     1.6  
     1.7 -    if (temp) {
     1.8 -        SDL_FreeSurface(temp);
     1.9 -    }
    1.10 +    SDL_FreeSurface(temp);
    1.11  
    1.12      return cursor;
    1.13  }
     2.1 --- a/src/render/SDL_yuv_sw.c	Thu Aug 29 08:29:21 2013 -0700
     2.2 +++ b/src/render/SDL_yuv_sw.c	Thu Aug 29 08:29:51 2013 -0700
     2.3 @@ -1012,10 +1012,8 @@
     2.4          break;
     2.5      }
     2.6  
     2.7 -    if (swdata->display) {
     2.8 -        SDL_FreeSurface(swdata->display);
     2.9 -        swdata->display = NULL;
    2.10 -    }
    2.11 +    SDL_FreeSurface(swdata->display);
    2.12 +    swdata->display = NULL;
    2.13      return 0;
    2.14  }
    2.15  
    2.16 @@ -1338,12 +1336,8 @@
    2.17          SDL_free(swdata->pixels);
    2.18          SDL_free(swdata->colortab);
    2.19          SDL_free(swdata->rgb_2_pix);
    2.20 -        if (swdata->stretch) {
    2.21 -            SDL_FreeSurface(swdata->stretch);
    2.22 -        }
    2.23 -        if (swdata->display) {
    2.24 -            SDL_FreeSurface(swdata->display);
    2.25 -        }
    2.26 +        SDL_FreeSurface(swdata->stretch);
    2.27 +        SDL_FreeSurface(swdata->display);
    2.28          SDL_free(swdata);
    2.29      }
    2.30  }
     3.1 --- a/src/video/SDL_bmp.c	Thu Aug 29 08:29:21 2013 -0700
     3.2 +++ b/src/video/SDL_bmp.c	Thu Aug 29 08:29:51 2013 -0700
     3.3 @@ -398,9 +398,7 @@
     3.4          if (src) {
     3.5              SDL_RWseek(src, fp_offset, RW_SEEK_SET);
     3.6          }
     3.7 -        if (surface) {
     3.8 -            SDL_FreeSurface(surface);
     3.9 -        }
    3.10 +        SDL_FreeSurface(surface);
    3.11          surface = NULL;
    3.12      }
    3.13      if (freesrc && src) {
     4.1 --- a/src/video/SDL_video.c	Thu Aug 29 08:29:21 2013 -0700
     4.2 +++ b/src/video/SDL_video.c	Thu Aug 29 08:29:51 2013 -0700
     4.3 @@ -1432,9 +1432,7 @@
     4.4          return;
     4.5      }
     4.6  
     4.7 -    if (window->icon) {
     4.8 -        SDL_FreeSurface(window->icon);
     4.9 -    }
    4.10 +    SDL_FreeSurface(window->icon);
    4.11  
    4.12      /* Convert the icon into ARGB8888 */
    4.13      window->icon = SDL_ConvertSurfaceFormat(icon, SDL_PIXELFORMAT_ARGB8888, 0);
    4.14 @@ -2183,9 +2181,7 @@
    4.15  
    4.16      /* Free memory associated with the window */
    4.17      SDL_free(window->title);
    4.18 -    if (window->icon) {
    4.19 -        SDL_FreeSurface(window->icon);
    4.20 -    }
    4.21 +    SDL_FreeSurface(window->icon);
    4.22      SDL_free(window->gamma);
    4.23      while (window->data) {
    4.24          SDL_WindowUserData *data = window->data;
     5.1 --- a/src/video/directfb/SDL_DirectFB_window.c	Thu Aug 29 08:29:21 2013 -0700
     5.2 +++ b/src/video/directfb/SDL_DirectFB_window.c	Thu Aug 29 08:29:51 2013 -0700
     5.3 @@ -237,8 +237,7 @@
     5.4      }
     5.5      return;
     5.6    error:
     5.7 -    if (surface)
     5.8 -        SDL_FreeSurface(surface);
     5.9 +    SDL_FreeSurface(surface);
    5.10      SDL_DFB_RELEASE(windata->icon);
    5.11      return;
    5.12  }
     6.1 --- a/src/video/dummy/SDL_nullframebuffer.c	Thu Aug 29 08:29:21 2013 -0700
     6.2 +++ b/src/video/dummy/SDL_nullframebuffer.c	Thu Aug 29 08:29:51 2013 -0700
     6.3 @@ -38,9 +38,7 @@
     6.4  
     6.5      /* Free the old framebuffer surface */
     6.6      surface = (SDL_Surface *) SDL_GetWindowData(window, DUMMY_SURFACE);
     6.7 -    if (surface) {
     6.8 -        SDL_FreeSurface(surface);
     6.9 -    }
    6.10 +    SDL_FreeSurface(surface);
    6.11  
    6.12      /* Create a new one */
    6.13      SDL_PixelFormatEnumToMasks(surface_format, &bpp, &Rmask, &Gmask, &Bmask, &Amask);
    6.14 @@ -83,9 +81,7 @@
    6.15      SDL_Surface *surface;
    6.16  
    6.17      surface = (SDL_Surface *) SDL_SetWindowData(window, DUMMY_SURFACE, NULL);
    6.18 -    if (surface) {
    6.19 -        SDL_FreeSurface(surface);
    6.20 -    }
    6.21 +    SDL_FreeSurface(surface);
    6.22  }
    6.23  
    6.24  #endif /* SDL_VIDEO_DRIVER_DUMMY */
     7.1 --- a/test/testautomation_render.c	Thu Aug 29 08:29:21 2013 -0700
     7.2 +++ b/test/testautomation_render.c	Thu Aug 29 08:29:51 2013 -0700
     7.3 @@ -190,10 +190,8 @@
     7.4     _compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE );
     7.5  
     7.6     /* Clean up. */
     7.7 -   if (referenceSurface != NULL) {
     7.8 -      SDL_FreeSurface(referenceSurface);
     7.9 -      referenceSurface = NULL;
    7.10 -   }
    7.11 +   SDL_FreeSurface(referenceSurface);
    7.12 +   referenceSurface = NULL;
    7.13  
    7.14     return TEST_COMPLETED;
    7.15  }
    7.16 @@ -333,10 +331,8 @@
    7.17     _compare(referenceSurface, ALLOWABLE_ERROR_BLENDED );
    7.18  
    7.19     /* Clean up. */
    7.20 -   if (referenceSurface != NULL) {
    7.21 -      SDL_FreeSurface(referenceSurface);
    7.22 -      referenceSurface = NULL;
    7.23 -   }
    7.24 +   SDL_FreeSurface(referenceSurface);
    7.25 +   referenceSurface = NULL;
    7.26  
    7.27     return TEST_COMPLETED;
    7.28  }
    7.29 @@ -400,10 +396,8 @@
    7.30  
    7.31     /* Clean up. */
    7.32     SDL_DestroyTexture( tface );
    7.33 -   if (referenceSurface != NULL) {
    7.34 -      SDL_FreeSurface(referenceSurface);
    7.35 -      referenceSurface = NULL;
    7.36 -   }
    7.37 +   SDL_FreeSurface(referenceSurface);
    7.38 +   referenceSurface = NULL;
    7.39  
    7.40     return TEST_COMPLETED;
    7.41  }
    7.42 @@ -470,10 +464,8 @@
    7.43  
    7.44     /* Clean up. */
    7.45     SDL_DestroyTexture( tface );
    7.46 -   if (referenceSurface != NULL) {
    7.47 -      SDL_FreeSurface(referenceSurface);
    7.48 -      referenceSurface = NULL;
    7.49 -   }
    7.50 +   SDL_FreeSurface(referenceSurface);
    7.51 +   referenceSurface = NULL;
    7.52  
    7.53     return TEST_COMPLETED;
    7.54  }
    7.55 @@ -543,10 +535,8 @@
    7.56  
    7.57     /* Clean up. */
    7.58     SDL_DestroyTexture( tface );
    7.59 -   if (referenceSurface != NULL) {
    7.60 -      SDL_FreeSurface(referenceSurface);
    7.61 -      referenceSurface = NULL;
    7.62 -   }
    7.63 +   SDL_FreeSurface(referenceSurface);
    7.64 +   referenceSurface = NULL;
    7.65  
    7.66     return TEST_COMPLETED;
    7.67  }
    7.68 @@ -655,37 +645,29 @@
    7.69     _testBlitBlendMode( tface, SDL_BLENDMODE_NONE );
    7.70     referenceSurface = SDLTest_ImageBlitBlendNone();
    7.71     _compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE );
    7.72 -   if (referenceSurface != NULL) {
    7.73 -      SDL_FreeSurface(referenceSurface);
    7.74 -      referenceSurface = NULL;
    7.75 -   }
    7.76 +   SDL_FreeSurface(referenceSurface);
    7.77 +   referenceSurface = NULL;
    7.78  
    7.79     /* Test Blend. */
    7.80     _testBlitBlendMode( tface, SDL_BLENDMODE_BLEND );
    7.81     referenceSurface = SDLTest_ImageBlitBlend();
    7.82     _compare(referenceSurface, ALLOWABLE_ERROR_BLENDED );
    7.83 -   if (referenceSurface != NULL) {
    7.84 -      SDL_FreeSurface(referenceSurface);
    7.85 -      referenceSurface = NULL;
    7.86 -   }
    7.87 +   SDL_FreeSurface(referenceSurface);
    7.88 +   referenceSurface = NULL;
    7.89  
    7.90     /* Test Add. */
    7.91     _testBlitBlendMode( tface, SDL_BLENDMODE_ADD );
    7.92     referenceSurface = SDLTest_ImageBlitBlendAdd();
    7.93     _compare(referenceSurface, ALLOWABLE_ERROR_BLENDED );
    7.94 -   if (referenceSurface != NULL) {
    7.95 -      SDL_FreeSurface(referenceSurface);
    7.96 -      referenceSurface = NULL;
    7.97 -   }
    7.98 +   SDL_FreeSurface(referenceSurface);
    7.99 +   referenceSurface = NULL;
   7.100  
   7.101     /* Test Mod. */
   7.102     _testBlitBlendMode( tface, SDL_BLENDMODE_MOD);
   7.103     referenceSurface = SDLTest_ImageBlitBlendMod();
   7.104     _compare(referenceSurface, ALLOWABLE_ERROR_BLENDED );
   7.105 -   if (referenceSurface != NULL) {
   7.106 -      SDL_FreeSurface(referenceSurface);
   7.107 -      referenceSurface = NULL;
   7.108 -   }
   7.109 +   SDL_FreeSurface(referenceSurface);
   7.110 +   referenceSurface = NULL;
   7.111  
   7.112     /* Clear surface. */
   7.113     _clearScreen();
   7.114 @@ -733,10 +715,8 @@
   7.115     /* Check to see if final image matches. */
   7.116     referenceSurface = SDLTest_ImageBlitBlendAll();
   7.117     _compare(referenceSurface, ALLOWABLE_ERROR_BLENDED);
   7.118 -   if (referenceSurface != NULL) {
   7.119 -      SDL_FreeSurface(referenceSurface);
   7.120 -      referenceSurface = NULL;
   7.121 -   }
   7.122 +   SDL_FreeSurface(referenceSurface);
   7.123 +   referenceSurface = NULL;
   7.124  
   7.125     return TEST_COMPLETED;
   7.126  }
   7.127 @@ -996,9 +976,7 @@
   7.128  
   7.129     /* Clean up. */
   7.130     SDL_free(pixels);
   7.131 -   if (testSurface != NULL) {
   7.132 -       SDL_FreeSurface(testSurface);
   7.133 -   }
   7.134 +   SDL_FreeSurface(testSurface);
   7.135  }
   7.136  
   7.137  /**
     8.1 --- a/test/testautomation_surface.c	Thu Aug 29 08:29:21 2013 -0700
     8.2 +++ b/test/testautomation_surface.c	Thu Aug 29 08:29:51 2013 -0700
     8.3 @@ -63,14 +63,10 @@
     8.4  void
     8.5  _surfaceTearDown(void *arg)
     8.6  {
     8.7 -    if (referenceSurface != NULL) {
     8.8 -        SDL_FreeSurface(referenceSurface);
     8.9 -        referenceSurface = NULL;
    8.10 -    }
    8.11 -    if (testSurface != NULL) {
    8.12 -        SDL_FreeSurface(testSurface);
    8.13 -        testSurface = NULL;
    8.14 -    }
    8.15 +    SDL_FreeSurface(referenceSurface);
    8.16 +    referenceSurface = NULL;
    8.17 +    SDL_FreeSurface(testSurface);
    8.18 +    testSurface = NULL;
    8.19  }
    8.20  
    8.21  /**
    8.22 @@ -193,10 +189,8 @@
    8.23      SDLTest_AssertCheck(checkFailCount4 == 0, "Validate results from calls to SDL_SetSurfaceBlendMode, expected: 0, got: %i", checkFailCount4);
    8.24  
    8.25      /* Clean up */
    8.26 -    if (face != NULL) {
    8.27 -        SDL_FreeSurface(face);
    8.28 -        face = NULL;
    8.29 -    }
    8.30 +    SDL_FreeSurface(face);
    8.31 +    face = NULL;
    8.32  }
    8.33  
    8.34  /* Helper to check that a file exists */
    8.35 @@ -250,14 +244,10 @@
    8.36      unlink(sampleFilename);
    8.37  
    8.38      /* Clean up */
    8.39 -    if (face != NULL) {
    8.40      SDL_FreeSurface(face);
    8.41      face = NULL;
    8.42 -    }
    8.43 -    if (rface != NULL) {
    8.44      SDL_FreeSurface(rface);
    8.45      rface = NULL;
    8.46 -    }
    8.47  
    8.48      return TEST_COMPLETED;
    8.49  }
    8.50 @@ -294,14 +284,10 @@
    8.51      SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
    8.52  
    8.53      /* Clean up. */
    8.54 -    if (face != NULL) {
    8.55 -        SDL_FreeSurface( face );
    8.56 -        face = NULL;
    8.57 -    }
    8.58 -    if (rface != NULL) {
    8.59 -        SDL_FreeSurface( rface );
    8.60 -        rface = NULL;
    8.61 -    }
    8.62 +    SDL_FreeSurface(face);
    8.63 +    face = NULL;
    8.64 +    SDL_FreeSurface(rface);
    8.65 +    rface = NULL;
    8.66  
    8.67      return TEST_COMPLETED;
    8.68  }
    8.69 @@ -427,9 +413,7 @@
    8.70     SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
    8.71  
    8.72     /* Clean up. */
    8.73 -   if (compareSurface != NULL) {
    8.74 -    SDL_FreeSurface( compareSurface );
    8.75 -   }
    8.76 +   SDL_FreeSurface(compareSurface);
    8.77  
    8.78     return TEST_COMPLETED;
    8.79  }
    8.80 @@ -452,9 +436,7 @@
    8.81     SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
    8.82  
    8.83     /* Clean up. */
    8.84 -   if (compareSurface != NULL) {
    8.85 -    SDL_FreeSurface( compareSurface );
    8.86 -   }
    8.87 +   SDL_FreeSurface(compareSurface);
    8.88  
    8.89     return TEST_COMPLETED;
    8.90  }
    8.91 @@ -477,9 +459,7 @@
    8.92     SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
    8.93  
    8.94     /* Clean up. */
    8.95 -   if (compareSurface != NULL) {
    8.96 -    SDL_FreeSurface( compareSurface );
    8.97 -   }
    8.98 +   SDL_FreeSurface(compareSurface);
    8.99  
   8.100     return TEST_COMPLETED;
   8.101  }
   8.102 @@ -503,9 +483,7 @@
   8.103     SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
   8.104  
   8.105     /* Clean up. */
   8.106 -   if (compareSurface != NULL) {
   8.107 -    SDL_FreeSurface( compareSurface );
   8.108 -   }
   8.109 +   SDL_FreeSurface(compareSurface);
   8.110  
   8.111     return TEST_COMPLETED;
   8.112  }
   8.113 @@ -528,9 +506,7 @@
   8.114     SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
   8.115  
   8.116     /* Clean up. */
   8.117 -   if (compareSurface != NULL) {
   8.118 -    SDL_FreeSurface( compareSurface );
   8.119 -   }
   8.120 +   SDL_FreeSurface(compareSurface);
   8.121  
   8.122     return TEST_COMPLETED;
   8.123  }
   8.124 @@ -553,9 +529,7 @@
   8.125     SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
   8.126  
   8.127     /* Clean up. */
   8.128 -   if (compareSurface != NULL) {
   8.129 -    SDL_FreeSurface( compareSurface );
   8.130 -   }
   8.131 +   SDL_FreeSurface(compareSurface);
   8.132  
   8.133     return TEST_COMPLETED;
   8.134  }
   8.135 @@ -578,9 +552,7 @@
   8.136     SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
   8.137  
   8.138     /* Clean up. */
   8.139 -   if (compareSurface != NULL) {
   8.140 -      SDL_FreeSurface( compareSurface );
   8.141 -   }
   8.142 +   SDL_FreeSurface(compareSurface);
   8.143  
   8.144     return TEST_COMPLETED;
   8.145  }
   8.146 @@ -603,9 +575,7 @@
   8.147     SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
   8.148  
   8.149     /* Clean up. */
   8.150 -   if (compareSurface != NULL) {
   8.151 -     SDL_FreeSurface(compareSurface);
   8.152 -   }
   8.153 +   SDL_FreeSurface(compareSurface);
   8.154  
   8.155     return TEST_COMPLETED;
   8.156  
     9.1 --- a/test/testshape.c	Thu Aug 29 08:29:21 2013 -0700
     9.2 +++ b/test/testshape.c	Thu Aug 29 08:29:51 2013 -0700
     9.3 @@ -90,8 +90,7 @@
     9.4          if(pictures[i].surface == NULL) {
     9.5              j = 0;
     9.6              for(j=0;j<num_pictures;j++)
     9.7 -                if(pictures[j].surface != NULL)
     9.8 -                    SDL_FreeSurface(pictures[j].surface);
     9.9 +                SDL_FreeSurface(pictures[j].surface);
    9.10              SDL_free(pictures);
    9.11              SDL_VideoQuit();
    9.12              SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not load surface from named bitmap file.");