mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-05-02 22:30:13 +02:00
Don't do NULL-checks before SDL_free()
Replaces the pattern
if (ptr) {
SDL_free(ptr);
}
with
SDL_free(ptr);
This commit is contained in:
committed by
Sam Lantinga
parent
2f810e0a5f
commit
aaee09d6ed
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
@@ -963,12 +959,8 @@ err:
|
||||
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
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user