Skip to content

Commit

Permalink
Christoph Mallon: Remove pointless if (x) before SDL_free(x)
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Aug 29, 2013
1 parent 1d2c779 commit f79fc33
Show file tree
Hide file tree
Showing 63 changed files with 157 additions and 349 deletions.
8 changes: 2 additions & 6 deletions src/SDL_hints.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
12 changes: 3 additions & 9 deletions src/audio/SDL_audio.c
Expand Up @@ -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)
Expand Down Expand Up @@ -632,9 +630,7 @@ free_device_list(char ***devices, int *devCount)
}
}

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

*devices = NULL;
*devCount = 0;
Expand Down Expand Up @@ -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);
}
Expand Down
20 changes: 6 additions & 14 deletions src/audio/SDL_wave.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand Down
6 changes: 2 additions & 4 deletions src/audio/alsa/SDL_alsa_audio.c
Expand Up @@ -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);
Expand Down
6 changes: 2 additions & 4 deletions src/audio/arts/SDL_artsaudio.c
Expand Up @@ -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;
Expand Down
6 changes: 2 additions & 4 deletions src/audio/bsd/SDL_bsdaudio.c
Expand Up @@ -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;
Expand Down
6 changes: 2 additions & 4 deletions src/audio/disk/SDL_diskaudio.c
Expand Up @@ -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;
Expand Down
6 changes: 2 additions & 4 deletions src/audio/dsp/SDL_dspaudio.c
Expand Up @@ -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;
Expand Down
6 changes: 2 additions & 4 deletions src/audio/esd/SDL_esdaudio.c
Expand Up @@ -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;
Expand Down
6 changes: 2 additions & 4 deletions src/audio/fusionsound/SDL_fsaudio.c
Expand Up @@ -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;
Expand Down
6 changes: 2 additions & 4 deletions src/audio/nas/SDL_nasaudio.c
Expand Up @@ -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;
Expand Down
6 changes: 2 additions & 4 deletions src/audio/paudio/SDL_paudio.c
Expand Up @@ -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;
Expand Down
6 changes: 2 additions & 4 deletions src/audio/pulseaudio/SDL_pulseaudio.c
Expand Up @@ -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);
Expand Down
6 changes: 2 additions & 4 deletions src/audio/qsa/SDL_qsa_audio.c
Expand Up @@ -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;
Expand Down
6 changes: 2 additions & 4 deletions src/audio/sndio/SDL_sndioaudio.c
Expand Up @@ -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;
Expand Down
12 changes: 4 additions & 8 deletions src/audio/sun/SDL_sunaudio.c
Expand Up @@ -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;
Expand Down
8 changes: 3 additions & 5 deletions src/audio/winmm/SDL_winmm.c
Expand Up @@ -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);
Expand Down
4 changes: 1 addition & 3 deletions src/audio/xaudio2/SDL_xaudio2.c
Expand Up @@ -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);
}
Expand Down
6 changes: 2 additions & 4 deletions src/events/SDL_events.c
Expand Up @@ -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) {
Expand Down
6 changes: 2 additions & 4 deletions src/events/SDL_touch.c
Expand Up @@ -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: */
6 changes: 2 additions & 4 deletions src/file/SDL_rwops.c
Expand Up @@ -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);
Expand Down
4 changes: 1 addition & 3 deletions src/filesystem/unix/SDL_sysfilesystem.c
Expand Up @@ -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;
}

Expand Down
6 changes: 2 additions & 4 deletions src/haptic/SDL_haptic.c
Expand Up @@ -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;
}

Expand Down

0 comments on commit f79fc33

Please sign in to comment.