Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions src/audio/openslES/SDL_openslES.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,7 @@ static void OPENSLES_DestroyPCMRecorder(SDL_AudioDevice *device)
audiodata->playsem = NULL;
}

if (audiodata->mixbuff) {
SDL_free(audiodata->mixbuff);
}
SDL_free(audiodata->mixbuff);
}

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

if (audiodata->mixbuff) {
SDL_free(audiodata->mixbuff);
}
SDL_free(audiodata->mixbuff);
}

static bool OPENSLES_CreatePCMPlayer(SDL_AudioDevice *device)
Expand Down
8 changes: 2 additions & 6 deletions src/audio/pipewire/SDL_pipewire.c
Original file line number Diff line number Diff line change
Expand Up @@ -635,16 +635,12 @@ static int metadata_property(void *object, Uint32 subject, const char *key, cons

if (subject == PW_ID_CORE && key && value) {
if (!SDL_strcmp(key, "default.audio.sink")) {
if (pipewire_default_sink_id) {
SDL_free(pipewire_default_sink_id);
}
SDL_free(pipewire_default_sink_id);
pipewire_default_sink_id = get_name_from_json(value);
node->persist = true;
change_default_device(pipewire_default_sink_id);
} else if (!SDL_strcmp(key, "default.audio.source")) {
if (pipewire_default_source_id) {
SDL_free(pipewire_default_source_id);
}
SDL_free(pipewire_default_source_id);
pipewire_default_source_id = get_name_from_json(value);
node->persist = true;
change_default_device(pipewire_default_source_id);
Expand Down
4 changes: 1 addition & 3 deletions src/core/linux/SDL_evdev_kbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -534,9 +534,7 @@ void SDL_EVDEV_kbd_quit(SDL_EVDEV_keyboard_state *state)
if (state->key_maps && state->key_maps != default_key_maps) {
int i;
for (i = 0; i < MAX_NR_KEYMAPS; ++i) {
if (state->key_maps[i]) {
SDL_free(state->key_maps[i]);
}
SDL_free(state->key_maps[i]);
}
SDL_free(state->key_maps);
}
Expand Down
4 changes: 1 addition & 3 deletions src/core/linux/SDL_ibus.c
Original file line number Diff line number Diff line change
Expand Up @@ -563,9 +563,7 @@ bool SDL_IBus_Init(void)
return false;
}

if (ibus_addr_file) {
SDL_free(ibus_addr_file);
}
SDL_free(ibus_addr_file);
ibus_addr_file = SDL_strdup(addr_file);

if (inotify_fd < 0) {
Expand Down
4 changes: 1 addition & 3 deletions src/dialog/unix/SDL_zenitymessagebox.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,7 @@ bool SDL_Zenity_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *bu
if (buttonID) {
char *output = SDL_ReadProcess(process, NULL, &exit_code);
if (exit_code < 0 || exit_code == 255) {
if (output) {
SDL_free(output);
}
SDL_free(output);
} else if (output) {
// It likes to add a newline...
char *tmp = SDL_strrchr(output, '\n');
Expand Down
18 changes: 5 additions & 13 deletions src/dialog/windows/SDL_windowsdialog.c
Original file line number Diff line number Diff line change
Expand Up @@ -731,25 +731,17 @@ bool windows_ShowModernFileFolderDialog(SDL_FileDialogType dialog_type, const ch
// default_file_w is a pointer into default_folder_w.
if (default_folder_w) {
SDL_free(default_folder_w);
} else if (default_file_w) {
} else {
SDL_free(default_file_w);
}

if (title_w) {
SDL_free(title_w);
}
SDL_free(title_w);

if (accept_w) {
SDL_free(accept_w);
}
SDL_free(accept_w);

if (cancel_w) {
SDL_free(cancel_w);
}
SDL_free(cancel_w);

if (filter_data) {
SDL_free(filter_data);
}
SDL_free(filter_data);

if (files) {
for (char** files_ptr = files; *files_ptr; files_ptr++) {
Expand Down
16 changes: 4 additions & 12 deletions src/gpu/d3d12/SDL_gpu_d3d12.c
Original file line number Diff line number Diff line change
Expand Up @@ -1349,9 +1349,7 @@ static void D3D12_INTERNAL_ReleaseBufferContainer(
}

// Containers are just client handles, so we can free immediately
if (container->debugName) {
SDL_free(container->debugName);
}
SDL_free(container->debugName);
SDL_free(container->buffers);
SDL_free(container);

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

// Containers are just client handles, so we can destroy immediately
if (container->debugName) {
SDL_free(container->debugName);
}
SDL_free(container->debugName);
SDL_free(container->textures);
SDL_free(container);

Expand Down Expand Up @@ -2072,9 +2068,7 @@ static void D3D12_SetBufferName(
D3D12BufferContainer *container = (D3D12BufferContainer *)buffer;

if (renderer->debug_mode && text != NULL) {
if (container->debugName != NULL) {
SDL_free(container->debugName);
}
SDL_free(container->debugName);

container->debugName = SDL_strdup(text);

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

if (renderer->debug_mode && text != NULL) {
if (container->debugName != NULL) {
SDL_free(container->debugName);
}
SDL_free(container->debugName);

container->debugName = SDL_strdup(text);

Expand Down
8 changes: 2 additions & 6 deletions src/gpu/vulkan/SDL_gpu_vulkan.c
Original file line number Diff line number Diff line change
Expand Up @@ -4958,9 +4958,7 @@ static void VULKAN_DestroyDevice(
j);
}

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

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

// Containers are just client handles, so we can destroy immediately
if (vulkanTextureContainer->debugName != NULL) {
SDL_free(vulkanTextureContainer->debugName);
}
SDL_free(vulkanTextureContainer->debugName);
SDL_free(vulkanTextureContainer->textures);
SDL_free(vulkanTextureContainer);

Expand Down
4 changes: 1 addition & 3 deletions src/hidapi/SDL_hidapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1041,9 +1041,7 @@ static void SDLCALL OnlyControllersChanged(void *userdata, const char *name, con

static void SDLCALL IgnoredDevicesChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
{
if (SDL_hidapi_ignored_devices) {
SDL_free(SDL_hidapi_ignored_devices);
}
SDL_free(SDL_hidapi_ignored_devices);
if (hint && *hint) {
SDL_hidapi_ignored_devices = SDL_strdup(hint);
} else {
Expand Down
4 changes: 1 addition & 3 deletions src/hidapi/windows/hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -991,9 +991,7 @@ struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned shor
break;
}

if (device_interface_list != NULL) {
free(device_interface_list);
}
free(device_interface_list); // This should NOT be SDL_free()

device_interface_list = (wchar_t*)calloc(len, sizeof(wchar_t));
if (device_interface_list == NULL) {
Expand Down
4 changes: 1 addition & 3 deletions src/io/SDL_iostream.c
Original file line number Diff line number Diff line change
Expand Up @@ -1177,9 +1177,7 @@ static bool SDLCALL dynamic_mem_close(void *userdata)
{
const IOStreamDynamicMemData *iodata = (IOStreamDynamicMemData *) userdata;
void *mem = SDL_GetPointerProperty(SDL_GetIOProperties(iodata->stream), SDL_PROP_IOSTREAM_DYNAMIC_MEMORY_POINTER, NULL);
if (mem) {
SDL_free(mem);
}
SDL_free(mem);
SDL_free(userdata);
return true;
}
Expand Down
4 changes: 1 addition & 3 deletions src/joystick/SDL_joystick.c
Original file line number Diff line number Diff line change
Expand Up @@ -3851,9 +3851,7 @@ static void SDL_LoadVIDPIDListFromHint(const char *hint, int *num_entries, int *
(*entries)[(*num_entries)++] = entry;
}

if (file) {
SDL_free(file);
}
SDL_free(file);
}

void SDL_LoadVIDPIDListFromHints(SDL_vidpid_list *list, const char *included_list, const char *excluded_list)
Expand Down
8 changes: 2 additions & 6 deletions src/joystick/hidapi/SDL_hidapi_combined.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ static bool HIDAPI_DriverCombined_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Jo
child = device->children[i];
child->driver->CloseJoystick(child, joystick);
}
if (serial) {
SDL_free(serial);
}
SDL_free(serial);
return false;
}

Expand All @@ -102,9 +100,7 @@ static bool HIDAPI_DriverCombined_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Jo
}

// Update the joystick with the combined serial numbers
if (joystick->serial) {
SDL_free(joystick->serial);
}
SDL_free(joystick->serial);
joystick->serial = serial;

return true;
Expand Down
20 changes: 5 additions & 15 deletions src/joystick/hidapi/SDL_hidapi_gip.c
Original file line number Diff line number Diff line change
Expand Up @@ -797,28 +797,18 @@ static bool GIP_AttachmentIsController(GIP_Attachment *attachment)

static void GIP_MetadataFree(GIP_Metadata *metadata)
{
if (metadata->device.audio_formats) {
SDL_free(metadata->device.audio_formats);
}
SDL_free(metadata->device.audio_formats);
if (metadata->device.preferred_types) {
int i;
for (i = 0; i < metadata->device.num_preferred_types; i++) {
if (metadata->device.preferred_types[i]) {
SDL_free(metadata->device.preferred_types[i]);
}
SDL_free(metadata->device.preferred_types[i]);
}
SDL_free(metadata->device.preferred_types);
}
if (metadata->device.supported_interfaces) {
SDL_free(metadata->device.supported_interfaces);
}
if (metadata->device.hid_descriptor) {
SDL_free(metadata->device.hid_descriptor);
}
SDL_free(metadata->device.supported_interfaces);
SDL_free(metadata->device.hid_descriptor);

if (metadata->message_metadata) {
SDL_free(metadata->message_metadata);
}
SDL_free(metadata->message_metadata);
SDL_memset(metadata, 0, sizeof(*metadata));
}

Expand Down
8 changes: 2 additions & 6 deletions src/joystick/linux/SDL_sysjoystick.c
Original file line number Diff line number Diff line change
Expand Up @@ -354,12 +354,8 @@ static bool IsJoystick(const char *path, int *fd, char **name_return, Uint16 *ve
return true;

error:
if (driver) {
SDL_free(driver);
}
if (name) {
SDL_free(name);
}
SDL_free(driver);
SDL_free(name);
return false;
}

Expand Down
16 changes: 4 additions & 12 deletions src/joystick/windows/SDL_rawinputjoystick.c
Original file line number Diff line number Diff line change
Expand Up @@ -923,12 +923,8 @@ static void RAWINPUT_AddDevice(HANDLE hDevice)
device->name = SDL_CreateJoystickName(device->vendor_id, device->product_id, manufacturer_string, product_string);
device->guid = SDL_CreateJoystickGUID(SDL_HARDWARE_BUS_USB, device->vendor_id, device->product_id, device->version, manufacturer_string, product_string, 'r', 0);

if (manufacturer_string) {
SDL_free(manufacturer_string);
}
if (product_string) {
SDL_free(product_string);
}
SDL_free(manufacturer_string);
SDL_free(product_string);
}

device->path = SDL_strdup(dev_name);
Expand Down Expand Up @@ -963,12 +959,8 @@ static void RAWINPUT_AddDevice(HANDLE hDevice)
CloseHandle(hFile);
}
if (device) {
if (device->name) {
SDL_free(device->name);
}
if (device->path) {
SDL_free(device->path);
}
SDL_free(device->name);
SDL_free(device->path);
SDL_free(device);
}
#undef CHECK
Expand Down
4 changes: 1 addition & 3 deletions src/joystick/windows/SDL_windows_gaming_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -973,9 +973,7 @@ static void WGI_JoystickQuit(void)
while (wgi.controller_count > 0) {
IEventHandler_CRawGameControllerVtbl_InvokeRemoved(&controller_removed.iface, NULL, wgi.controllers[wgi.controller_count - 1].controller);
}
if (wgi.controllers) {
SDL_free(wgi.controllers);
}
SDL_free(wgi.controllers);

if (wgi.arcade_stick_statics) {
__x_ABI_CWindows_CGaming_CInput_CIArcadeStickStatics_Release(wgi.arcade_stick_statics);
Expand Down
4 changes: 1 addition & 3 deletions src/render/opengl/SDL_render_gl.c
Original file line number Diff line number Diff line change
Expand Up @@ -613,9 +613,7 @@ static bool GL_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_P
GL_CheckError("", renderer);
renderdata->glGenTextures(1, &data->texture);
if (!GL_CheckError("glGenTextures()", renderer)) {
if (data->pixels) {
SDL_free(data->pixels);
}
SDL_free(data->pixels);
SDL_free(data);
return false;
}
Expand Down
4 changes: 1 addition & 3 deletions src/render/opengles2/SDL_render_gles2.c
Original file line number Diff line number Diff line change
Expand Up @@ -1962,9 +1962,7 @@ static bool GLES2_TexSubImage2D(GLES2_RenderData *data, GLenum target, GLint xof
}

data->glTexSubImage2D(target, 0, xoffset, yoffset, width, height, format, type, src);
if (blob) {
SDL_free(blob);
}
SDL_free(blob);
return true;
}

Expand Down
4 changes: 1 addition & 3 deletions src/stdlib/SDL_getenv.c
Original file line number Diff line number Diff line change
Expand Up @@ -564,9 +564,7 @@ const char *SDL_getenv_unsafe(const char *name)
maxlen = length;
} else {
if (GetLastError() != ERROR_SUCCESS) {
if (string) {
SDL_free(string);
}
SDL_free(string);
return NULL;
}
break;
Expand Down
4 changes: 1 addition & 3 deletions src/test/SDL_test_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -2075,9 +2075,7 @@ static void SDLCALL SDLTest_ScreenShotClipboardCleanup(void *context)

SDL_Log("Cleaning up screenshot image data");

if (data->image) {
SDL_free(data->image);
}
SDL_free(data->image);
SDL_free(data);
}

Expand Down
4 changes: 1 addition & 3 deletions src/thread/n3ds/SDL_sysmutex.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ SDL_Mutex *SDL_CreateMutex(void)

void SDL_DestroyMutex(SDL_Mutex *mutex)
{
if (mutex) {
SDL_free(mutex);
}
SDL_free(mutex);
}

void SDL_LockMutex(SDL_Mutex *mutex) SDL_NO_THREAD_SAFETY_ANALYSIS // clang doesn't know about NULL mutexes
Expand Down
4 changes: 1 addition & 3 deletions src/tray/unix/SDL_tray.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,7 @@ SDL_Tray *SDL_CreateTray(SDL_Surface *icon, const char *tooltip)
SDL_free(sdl_dir);

tray_error:
if (tray) {
SDL_free(tray);
}
SDL_free(tray);

if (gtk) {
SDL_Gtk_ExitContext(gtk);
Expand Down
Loading
Loading