Skip to content
Permalink
Browse files

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

  • Loading branch information
slouken committed Aug 29, 2013
1 parent 1d2c779 commit f79fc33a392595f3dcff30ae2c9e5787980e579a
Showing with 157 additions and 349 deletions.
  1. +2 −6 src/SDL_hints.c
  2. +3 −9 src/audio/SDL_audio.c
  3. +6 −14 src/audio/SDL_wave.c
  4. +2 −4 src/audio/alsa/SDL_alsa_audio.c
  5. +2 −4 src/audio/arts/SDL_artsaudio.c
  6. +2 −4 src/audio/bsd/SDL_bsdaudio.c
  7. +2 −4 src/audio/disk/SDL_diskaudio.c
  8. +2 −4 src/audio/dsp/SDL_dspaudio.c
  9. +2 −4 src/audio/esd/SDL_esdaudio.c
  10. +2 −4 src/audio/fusionsound/SDL_fsaudio.c
  11. +2 −4 src/audio/nas/SDL_nasaudio.c
  12. +2 −4 src/audio/paudio/SDL_paudio.c
  13. +2 −4 src/audio/pulseaudio/SDL_pulseaudio.c
  14. +2 −4 src/audio/qsa/SDL_qsa_audio.c
  15. +2 −4 src/audio/sndio/SDL_sndioaudio.c
  16. +4 −8 src/audio/sun/SDL_sunaudio.c
  17. +3 −5 src/audio/winmm/SDL_winmm.c
  18. +1 −3 src/audio/xaudio2/SDL_xaudio2.c
  19. +2 −4 src/events/SDL_events.c
  20. +2 −4 src/events/SDL_touch.c
  21. +2 −4 src/file/SDL_rwops.c
  22. +1 −3 src/filesystem/unix/SDL_sysfilesystem.c
  23. +2 −4 src/haptic/SDL_haptic.c
  24. +8 −16 src/haptic/darwin/SDL_syshaptic.c
  25. +10 −20 src/haptic/windows/SDL_syshaptic.c
  26. +5 −14 src/joystick/SDL_joystick.c
  27. +2 −6 src/joystick/beos/SDL_bejoystick.cc
  28. +3 −7 src/joystick/bsd/SDL_sysjoystick.c
  29. +3 −5 src/joystick/windows/SDL_dxjoystick.c
  30. +5 −9 src/joystick/windows/SDL_mmjoystick.c
  31. +1 −3 src/render/SDL_render.c
  32. +3 −9 src/render/SDL_yuv_sw.c
  33. +1 −3 src/render/direct3d/SDL_render_d3d.c
  34. +1 −3 src/render/opengl/SDL_render_gl.c
  35. +2 −6 src/render/opengles/SDL_render_gles.c
  36. +2 −6 src/render/opengles2/SDL_render_gles2.c
  37. +1 −4 src/render/psp/SDL_render_psp.c
  38. +1 −3 src/render/software/SDL_render_sw.c
  39. +1 −1 src/stdlib/SDL_iconv.c
  40. +1 −3 src/test/SDL_test_common.c
  41. +2 −4 src/video/SDL_RLEaccel.c
  42. +1 −3 src/video/SDL_clipboard.c
  43. +3 −7 src/video/SDL_pixels.c
  44. +1 −1 src/video/SDL_surface.c
  45. +16 −36 src/video/SDL_video.c
  46. +2 −2 src/video/cocoa/SDL_cocoamodes.m
  47. +1 −3 src/video/cocoa/SDL_cocoavideo.m
  48. +1 −3 src/video/directfb/SDL_DirectFB_render.c
  49. +1 −1 src/video/directfb/SDL_DirectFB_video.h
  50. +1 −3 src/video/dummy/SDL_nullvideo.c
  51. +1 −3 src/video/uikit/SDL_uikitvideo.m
  52. +1 −3 src/video/windows/SDL_windowsmessagebox.c
  53. +1 −3 src/video/windows/SDL_windowsvideo.c
  54. +1 −3 src/video/windows/SDL_windowswindow.c
  55. +2 −4 src/video/x11/SDL_x11opengl.c
  56. +1 −3 src/video/x11/SDL_x11video.c
  57. +2 −6 test/testautomation.c
  58. +1 −3 test/testautomation_audio.c
  59. +6 −6 test/testautomation_clipboard.c
  60. +1 −3 test/testautomation_render.c
  61. +4 −4 test/testautomation_video.c
  62. +2 −6 test/testiconv.c
  63. +3 −9 test/testsprite2.c
@@ -72,9 +72,7 @@ SDL_SetHintWithPriority(const char *name, const char *value,
entry->callback(entry->userdata, name, hint->value, value);
entry = next;
}
if (hint->value) {
SDL_free(hint->value);
}
SDL_free(hint->value);
hint->value = value ? SDL_strdup(value) : NULL;
}
hint->priority = priority;
@@ -206,9 +204,7 @@ void SDL_ClearHints(void)
SDL_hints = hint->next;

SDL_free(hint->name);
if (hint->value) {
SDL_free(hint->value);
}
SDL_free(hint->value);
for (entry = hint->callbacks; entry; ) {
SDL_HintWatch *freeable = entry;
entry = entry->next;
@@ -300,9 +300,7 @@ SDL_StreamInit(SDL_AudioStreamer * stream, int max_len, Uint8 silence)
static void
SDL_StreamDeinit(SDL_AudioStreamer * stream)
{
if (stream->buffer != NULL) {
SDL_free(stream->buffer);
}
SDL_free(stream->buffer);
}

#if defined(ANDROID)
@@ -632,9 +630,7 @@ free_device_list(char ***devices, int *devCount)
}
}

if (*devices != NULL) {
SDL_free(*devices);
}
SDL_free(*devices);

*devices = NULL;
*devCount = 0;
@@ -761,9 +757,7 @@ close_audio_device(SDL_AudioDevice * device)
if (device->mixer_lock != NULL) {
SDL_DestroyMutex(device->mixer_lock);
}
if (device->fake_stream != NULL) {
SDL_FreeAudioMem(device->fake_stream);
}
SDL_FreeAudioMem(device->fake_stream);
if (device->convert.needed) {
SDL_FreeAudioMem(device->convert.buf);
}
@@ -449,10 +449,8 @@ SDL_LoadWAV_RW(SDL_RWops * src, int freesrc,
/* Read the audio data format chunk */
chunk.data = NULL;
do {
if (chunk.data != NULL) {
SDL_free(chunk.data);
chunk.data = NULL;
}
SDL_free(chunk.data);
chunk.data = NULL;
lenread = ReadChunk(src, &chunk);
if (lenread < 0) {
was_error = 1;
@@ -549,10 +547,8 @@ SDL_LoadWAV_RW(SDL_RWops * src, int freesrc,
/* Read the audio data chunk */
*audio_buf = NULL;
do {
if (*audio_buf != NULL) {
SDL_free(*audio_buf);
*audio_buf = NULL;
}
SDL_free(*audio_buf);
*audio_buf = NULL;
lenread = ReadChunk(src, &chunk);
if (lenread < 0) {
was_error = 1;
@@ -583,9 +579,7 @@ SDL_LoadWAV_RW(SDL_RWops * src, int freesrc,
*audio_len &= ~(samplesize - 1);

done:
if (format != NULL) {
SDL_free(format);
}
SDL_free(format);
if (src) {
if (freesrc) {
SDL_RWclose(src);
@@ -606,9 +600,7 @@ SDL_LoadWAV_RW(SDL_RWops * src, int freesrc,
void
SDL_FreeWAV(Uint8 * audio_buf)
{
if (audio_buf != NULL) {
SDL_free(audio_buf);
}
SDL_free(audio_buf);
}

static int
@@ -340,10 +340,8 @@ static void
ALSA_CloseDevice(_THIS)
{
if (this->hidden != NULL) {
if (this->hidden->mixbuf != NULL) {
SDL_FreeAudioMem(this->hidden->mixbuf);
this->hidden->mixbuf = NULL;
}
SDL_FreeAudioMem(this->hidden->mixbuf);
this->hidden->mixbuf = NULL;
if (this->hidden->pcm_handle) {
ALSA_snd_pcm_drain(this->hidden->pcm_handle);
ALSA_snd_pcm_close(this->hidden->pcm_handle);
@@ -204,10 +204,8 @@ static void
ARTS_CloseDevice(_THIS)
{
if (this->hidden != NULL) {
if (this->hidden->mixbuf != NULL) {
SDL_FreeAudioMem(this->hidden->mixbuf);
this->hidden->mixbuf = NULL;
}
SDL_FreeAudioMem(this->hidden->mixbuf);
this->hidden->mixbuf = NULL;
if (this->hidden->stream) {
SDL_NAME(arts_close_stream) (this->hidden->stream);
this->hidden->stream = 0;
@@ -214,10 +214,8 @@ static void
BSDAUDIO_CloseDevice(_THIS)
{
if (this->hidden != NULL) {
if (this->hidden->mixbuf != NULL) {
SDL_FreeAudioMem(this->hidden->mixbuf);
this->hidden->mixbuf = NULL;
}
SDL_FreeAudioMem(this->hidden->mixbuf);
this->hidden->mixbuf = NULL;
if (this->hidden->audio_fd >= 0) {
close(this->hidden->audio_fd);
this->hidden->audio_fd = -1;
@@ -88,10 +88,8 @@ static void
DISKAUD_CloseDevice(_THIS)
{
if (this->hidden != NULL) {
if (this->hidden->mixbuf != NULL) {
SDL_FreeAudioMem(this->hidden->mixbuf);
this->hidden->mixbuf = NULL;
}
SDL_FreeAudioMem(this->hidden->mixbuf);
this->hidden->mixbuf = NULL;
if (this->hidden->output != NULL) {
SDL_RWclose(this->hidden->output);
this->hidden->output = NULL;
@@ -61,10 +61,8 @@ static void
DSP_CloseDevice(_THIS)
{
if (this->hidden != NULL) {
if (this->hidden->mixbuf != NULL) {
SDL_FreeAudioMem(this->hidden->mixbuf);
this->hidden->mixbuf = NULL;
}
SDL_FreeAudioMem(this->hidden->mixbuf);
this->hidden->mixbuf = NULL;
if (this->hidden->audio_fd >= 0) {
close(this->hidden->audio_fd);
this->hidden->audio_fd = -1;
@@ -176,10 +176,8 @@ static void
ESD_CloseDevice(_THIS)
{
if (this->hidden != NULL) {
if (this->hidden->mixbuf != NULL) {
SDL_FreeAudioMem(this->hidden->mixbuf);
this->hidden->mixbuf = NULL;
}
SDL_FreeAudioMem(this->hidden->mixbuf);
this->hidden->mixbuf = NULL;
if (this->hidden->audio_fd >= 0) {
SDL_NAME(esd_close) (this->hidden->audio_fd);
this->hidden->audio_fd = -1;
@@ -169,10 +169,8 @@ static void
SDL_FS_CloseDevice(_THIS)
{
if (this->hidden != NULL) {
if (this->hidden->mixbuf != NULL) {
SDL_FreeAudioMem(this->hidden->mixbuf);
this->hidden->mixbuf = NULL;
}
SDL_FreeAudioMem(this->hidden->mixbuf);
this->hidden->mixbuf = NULL;
if (this->hidden->stream) {
this->hidden->stream->Release(this->hidden->stream);
this->hidden->stream = NULL;
@@ -191,10 +191,8 @@ static void
NAS_CloseDevice(_THIS)
{
if (this->hidden != NULL) {
if (this->hidden->mixbuf != NULL) {
SDL_FreeAudioMem(this->hidden->mixbuf);
this->hidden->mixbuf = NULL;
}
SDL_FreeAudioMem(this->hidden->mixbuf);
this->hidden->mixbuf = NULL;
if (this->hidden->aud) {
NAS_AuCloseServer(this->hidden->aud);
this->hidden->aud = 0;
@@ -231,10 +231,8 @@ static void
PAUDIO_CloseDevice(_THIS)
{
if (this->hidden != NULL) {
if (this->hidden->mixbuf != NULL) {
SDL_FreeAudioMem(this->hidden->mixbuf);
this->hidden->mixbuf = NULL;
}
SDL_FreeAudioMem(this->hidden->mixbuf);
this->hidden->mixbuf = NULL;
if (this->hidden->audio_fd >= 0) {
close(this->hidden->audio_fd);
this->hidden->audio_fd = -1;
@@ -300,10 +300,8 @@ static void
PULSEAUDIO_CloseDevice(_THIS)
{
if (this->hidden != NULL) {
if (this->hidden->mixbuf != NULL) {
SDL_FreeAudioMem(this->hidden->mixbuf);
this->hidden->mixbuf = NULL;
}
SDL_FreeAudioMem(this->hidden->mixbuf);
this->hidden->mixbuf = NULL;
if (this->hidden->stream) {
PULSEAUDIO_pa_stream_disconnect(this->hidden->stream);
PULSEAUDIO_pa_stream_unref(this->hidden->stream);
@@ -328,10 +328,8 @@ QSA_CloseDevice(_THIS)
this->hidden->audio_handle = NULL;
}

if (this->hidden->pcm_buf != NULL) {
SDL_FreeAudioMem(this->hidden->pcm_buf);
this->hidden->pcm_buf = NULL;
}
SDL_FreeAudioMem(this->hidden->pcm_buf);
this->hidden->pcm_buf = NULL;

SDL_free(this->hidden);
this->hidden = NULL;
@@ -181,10 +181,8 @@ static void
SNDIO_CloseDevice(_THIS)
{
if (this->hidden != NULL) {
if (this->hidden->mixbuf != NULL) {
SDL_FreeAudioMem(this->hidden->mixbuf);
this->hidden->mixbuf = NULL;
}
SDL_FreeAudioMem(this->hidden->mixbuf);
this->hidden->mixbuf = NULL;
if ( this->hidden->dev != NULL ) {
SNDIO_sio_close(this->hidden->dev);
this->hidden->dev = NULL;
@@ -184,14 +184,10 @@ static void
SUNAUDIO_CloseDevice(_THIS)
{
if (this->hidden != NULL) {
if (this->hidden->mixbuf != NULL) {
SDL_FreeAudioMem(this->hidden->mixbuf);
this->hidden->mixbuf = NULL;
}
if (this->hidden->ulaw_buf != NULL) {
SDL_free(this->hidden->ulaw_buf);
this->hidden->ulaw_buf = NULL;
}
SDL_FreeAudioMem(this->hidden->mixbuf);
this->hidden->mixbuf = NULL;
SDL_free(this->hidden->ulaw_buf);
this->hidden->ulaw_buf = NULL;
if (this->hidden->audio_fd >= 0) {
close(this->hidden->audio_fd);
this->hidden->audio_fd = -1;
@@ -176,11 +176,9 @@ WINMM_CloseDevice(_THIS)
}
}

if (this->hidden->mixbuf != NULL) {
/* Free raw mixing buffer */
SDL_free(this->hidden->mixbuf);
this->hidden->mixbuf = NULL;
}
/* Free raw mixing buffer */
SDL_free(this->hidden->mixbuf);
this->hidden->mixbuf = NULL;

if (this->hidden->hin) {
waveInClose(this->hidden->hin);
@@ -205,9 +205,7 @@ XAUDIO2_CloseDevice(_THIS)
if (ixa2 != NULL) {
IXAudio2_Release(ixa2);
}
if (this->hidden->mixbuf != NULL) {
SDL_free(this->hidden->mixbuf);
}
SDL_free(this->hidden->mixbuf);
if (this->hidden->semaphore != NULL) {
CloseHandle(this->hidden->semaphore);
}
@@ -141,10 +141,8 @@ SDL_StopEventLoop(void)

/* Clear disabled event state */
for (i = 0; i < SDL_arraysize(SDL_disabled_events); ++i) {
if (SDL_disabled_events[i]) {
SDL_free(SDL_disabled_events[i]);
SDL_disabled_events[i] = NULL;
}
SDL_free(SDL_disabled_events[i]);
SDL_disabled_events[i] = NULL;
}

while (SDL_event_watchers) {
@@ -355,10 +355,8 @@ SDL_TouchQuit(void)
}
SDL_assert(SDL_num_touch == 0);

if (SDL_touchDevices) {
SDL_free(SDL_touchDevices);
SDL_touchDevices = NULL;
}
SDL_free(SDL_touchDevices);
SDL_touchDevices = NULL;
}

/* vi: set ts=4 sw=4 expandtab: */
@@ -275,10 +275,8 @@ windows_file_close(SDL_RWops * context)
CloseHandle(context->hidden.windowsio.h);
context->hidden.windowsio.h = INVALID_HANDLE_VALUE; /* to be sure */
}
if (context->hidden.windowsio.buffer.data) {
SDL_free(context->hidden.windowsio.buffer.data);
context->hidden.windowsio.buffer.data = NULL;
}
SDL_free(context->hidden.windowsio.buffer.data);
context->hidden.windowsio.buffer.data = NULL;
SDL_FreeRW(context);
}
return (0);
@@ -69,9 +69,7 @@ readSymLink(const char *path)
len *= 2; /* grow buffer, try again. */
}

if (retval != NULL) {
SDL_free(retval);
}
SDL_free(retval);
return NULL;
}

@@ -379,10 +379,8 @@ void
SDL_HapticQuit(void)
{
SDL_SYS_HapticQuit();
if (SDL_haptics != NULL) {
SDL_free(SDL_haptics);
SDL_haptics = NULL;
}
SDL_free(SDL_haptics);
SDL_haptics = NULL;
SDL_numhaptics = 0;
}

0 comments on commit f79fc33

Please sign in to comment.