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:
Eddy Jansson
2025-10-19 11:07:48 +02:00
committed by Sam Lantinga
parent 2f810e0a5f
commit aaee09d6ed
40 changed files with 76 additions and 229 deletions

View File

@@ -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;

View File

@@ -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));
}