Skip to content

Commit f0cb361

Browse files
committed
Don't do NULL-checks before SDL_free()
Replaces the pattern if (ptr) { SDL_free(ptr); } with SDL_free(ptr);
1 parent cbcb145 commit f0cb361

40 files changed

+76
-229
lines changed

src/audio/openslES/SDL_openslES.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,7 @@ static void OPENSLES_DestroyPCMRecorder(SDL_AudioDevice *device)
223223
audiodata->playsem = NULL;
224224
}
225225

226-
if (audiodata->mixbuff) {
227-
SDL_free(audiodata->mixbuff);
228-
}
226+
SDL_free(audiodata->mixbuff);
229227
}
230228

231229
// !!! FIXME: make this non-blocking!
@@ -419,9 +417,7 @@ static void OPENSLES_DestroyPCMPlayer(SDL_AudioDevice *device)
419417
audiodata->playsem = NULL;
420418
}
421419

422-
if (audiodata->mixbuff) {
423-
SDL_free(audiodata->mixbuff);
424-
}
420+
SDL_free(audiodata->mixbuff);
425421
}
426422

427423
static bool OPENSLES_CreatePCMPlayer(SDL_AudioDevice *device)

src/audio/pipewire/SDL_pipewire.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -635,16 +635,12 @@ static int metadata_property(void *object, Uint32 subject, const char *key, cons
635635

636636
if (subject == PW_ID_CORE && key && value) {
637637
if (!SDL_strcmp(key, "default.audio.sink")) {
638-
if (pipewire_default_sink_id) {
639-
SDL_free(pipewire_default_sink_id);
640-
}
638+
SDL_free(pipewire_default_sink_id);
641639
pipewire_default_sink_id = get_name_from_json(value);
642640
node->persist = true;
643641
change_default_device(pipewire_default_sink_id);
644642
} else if (!SDL_strcmp(key, "default.audio.source")) {
645-
if (pipewire_default_source_id) {
646-
SDL_free(pipewire_default_source_id);
647-
}
643+
SDL_free(pipewire_default_source_id);
648644
pipewire_default_source_id = get_name_from_json(value);
649645
node->persist = true;
650646
change_default_device(pipewire_default_source_id);

src/core/linux/SDL_evdev_kbd.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -534,9 +534,7 @@ void SDL_EVDEV_kbd_quit(SDL_EVDEV_keyboard_state *state)
534534
if (state->key_maps && state->key_maps != default_key_maps) {
535535
int i;
536536
for (i = 0; i < MAX_NR_KEYMAPS; ++i) {
537-
if (state->key_maps[i]) {
538-
SDL_free(state->key_maps[i]);
539-
}
537+
SDL_free(state->key_maps[i]);
540538
}
541539
SDL_free(state->key_maps);
542540
}

src/core/linux/SDL_ibus.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -563,9 +563,7 @@ bool SDL_IBus_Init(void)
563563
return false;
564564
}
565565

566-
if (ibus_addr_file) {
567-
SDL_free(ibus_addr_file);
568-
}
566+
SDL_free(ibus_addr_file);
569567
ibus_addr_file = SDL_strdup(addr_file);
570568

571569
if (inotify_fd < 0) {

src/dialog/unix/SDL_zenitymessagebox.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,7 @@ bool SDL_Zenity_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *bu
161161
if (buttonID) {
162162
char *output = SDL_ReadProcess(process, NULL, &exit_code);
163163
if (exit_code < 0 || exit_code == 255) {
164-
if (output) {
165-
SDL_free(output);
166-
}
164+
SDL_free(output);
167165
} else if (output) {
168166
// It likes to add a newline...
169167
char *tmp = SDL_strrchr(output, '\n');

src/dialog/windows/SDL_windowsdialog.c

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -731,25 +731,15 @@ bool windows_ShowModernFileFolderDialog(SDL_FileDialogType dialog_type, const ch
731731
// default_file_w is a pointer into default_folder_w.
732732
if (default_folder_w) {
733733
SDL_free(default_folder_w);
734-
} else if (default_file_w) {
735-
SDL_free(default_file_w);
736-
}
734+
} else SDL_free(default_file_w);
737735

738-
if (title_w) {
739-
SDL_free(title_w);
740-
}
736+
SDL_free(title_w);
741737

742-
if (accept_w) {
743-
SDL_free(accept_w);
744-
}
738+
SDL_free(accept_w);
745739

746-
if (cancel_w) {
747-
SDL_free(cancel_w);
748-
}
740+
SDL_free(cancel_w);
749741

750-
if (filter_data) {
751-
SDL_free(filter_data);
752-
}
742+
SDL_free(filter_data);
753743

754744
if (files) {
755745
for (char** files_ptr = files; *files_ptr; files_ptr++) {

src/gpu/d3d12/SDL_gpu_d3d12.c

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,9 +1349,7 @@ static void D3D12_INTERNAL_ReleaseBufferContainer(
13491349
}
13501350

13511351
// Containers are just client handles, so we can free immediately
1352-
if (container->debugName) {
1353-
SDL_free(container->debugName);
1354-
}
1352+
SDL_free(container->debugName);
13551353
SDL_free(container->buffers);
13561354
SDL_free(container);
13571355

@@ -1426,9 +1424,7 @@ static void D3D12_INTERNAL_ReleaseTextureContainer(
14261424
SDL_DestroyProperties(container->header.info.props);
14271425

14281426
// Containers are just client handles, so we can destroy immediately
1429-
if (container->debugName) {
1430-
SDL_free(container->debugName);
1431-
}
1427+
SDL_free(container->debugName);
14321428
SDL_free(container->textures);
14331429
SDL_free(container);
14341430

@@ -2072,9 +2068,7 @@ static void D3D12_SetBufferName(
20722068
D3D12BufferContainer *container = (D3D12BufferContainer *)buffer;
20732069

20742070
if (renderer->debug_mode && text != NULL) {
2075-
if (container->debugName != NULL) {
2076-
SDL_free(container->debugName);
2077-
}
2071+
SDL_free(container->debugName);
20782072

20792073
container->debugName = SDL_strdup(text);
20802074

@@ -2096,9 +2090,7 @@ static void D3D12_SetTextureName(
20962090
D3D12TextureContainer *container = (D3D12TextureContainer *)texture;
20972091

20982092
if (renderer->debug_mode && text != NULL) {
2099-
if (container->debugName != NULL) {
2100-
SDL_free(container->debugName);
2101-
}
2093+
SDL_free(container->debugName);
21022094

21032095
container->debugName = SDL_strdup(text);
21042096

src/gpu/vulkan/SDL_gpu_vulkan.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4958,9 +4958,7 @@ static void VULKAN_DestroyDevice(
49584958
j);
49594959
}
49604960

4961-
if (renderer->memoryAllocator->subAllocators[i].allocations != NULL) {
4962-
SDL_free(renderer->memoryAllocator->subAllocators[i].allocations);
4963-
}
4961+
SDL_free(renderer->memoryAllocator->subAllocators[i].allocations);
49644962

49654963
SDL_free(renderer->memoryAllocator->subAllocators[i].sortedFreeRegions);
49664964
}
@@ -6987,9 +6985,7 @@ static void VULKAN_ReleaseTexture(
69876985
SDL_DestroyProperties(vulkanTextureContainer->header.info.props);
69886986

69896987
// Containers are just client handles, so we can destroy immediately
6990-
if (vulkanTextureContainer->debugName != NULL) {
6991-
SDL_free(vulkanTextureContainer->debugName);
6992-
}
6988+
SDL_free(vulkanTextureContainer->debugName);
69936989
SDL_free(vulkanTextureContainer->textures);
69946990
SDL_free(vulkanTextureContainer);
69956991

src/hidapi/SDL_hidapi.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,9 +1041,7 @@ static void SDLCALL OnlyControllersChanged(void *userdata, const char *name, con
10411041

10421042
static void SDLCALL IgnoredDevicesChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
10431043
{
1044-
if (SDL_hidapi_ignored_devices) {
1045-
SDL_free(SDL_hidapi_ignored_devices);
1046-
}
1044+
SDL_free(SDL_hidapi_ignored_devices);
10471045
if (hint && *hint) {
10481046
SDL_hidapi_ignored_devices = SDL_strdup(hint);
10491047
} else {

src/io/SDL_iostream.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,9 +1177,7 @@ static bool SDLCALL dynamic_mem_close(void *userdata)
11771177
{
11781178
const IOStreamDynamicMemData *iodata = (IOStreamDynamicMemData *) userdata;
11791179
void *mem = SDL_GetPointerProperty(SDL_GetIOProperties(iodata->stream), SDL_PROP_IOSTREAM_DYNAMIC_MEMORY_POINTER, NULL);
1180-
if (mem) {
1181-
SDL_free(mem);
1182-
}
1180+
SDL_free(mem);
11831181
SDL_free(userdata);
11841182
return true;
11851183
}

0 commit comments

Comments
 (0)