Procházet zdrojové kódy

Don't do NULL-checks before SDL_free()

Replaces the pattern

  if (ptr) {
    SDL_free(ptr);
  }

with

  SDL_free(ptr);
Eddy Jansson před 4 dny
rodič
revize
aaee09d6ed
40 změnil soubory, kde provedl 76 přidání a 229 odebrání
  1. 2 6
      src/audio/openslES/SDL_openslES.c
  2. 2 6
      src/audio/pipewire/SDL_pipewire.c
  3. 1 3
      src/core/linux/SDL_evdev_kbd.c
  4. 1 3
      src/core/linux/SDL_ibus.c
  5. 1 3
      src/dialog/unix/SDL_zenitymessagebox.c
  6. 5 15
      src/dialog/windows/SDL_windowsdialog.c
  7. 4 12
      src/gpu/d3d12/SDL_gpu_d3d12.c
  8. 2 6
      src/gpu/vulkan/SDL_gpu_vulkan.c
  9. 1 3
      src/hidapi/SDL_hidapi.c
  10. 1 3
      src/io/SDL_iostream.c
  11. 1 3
      src/joystick/SDL_joystick.c
  12. 2 6
      src/joystick/hidapi/SDL_hidapi_combined.c
  13. 5 15
      src/joystick/hidapi/SDL_hidapi_gip.c
  14. 2 6
      src/joystick/linux/SDL_sysjoystick.c
  15. 4 12
      src/joystick/windows/SDL_rawinputjoystick.c
  16. 1 3
      src/joystick/windows/SDL_windows_gaming_input.c
  17. 1 3
      src/render/opengl/SDL_render_gl.c
  18. 1 3
      src/render/opengles2/SDL_render_gles2.c
  19. 1 3
      src/stdlib/SDL_getenv.c
  20. 1 3
      src/test/SDL_test_common.c
  21. 1 3
      src/thread/n3ds/SDL_sysmutex.c
  22. 1 3
      src/tray/unix/SDL_tray.c
  23. 1 3
      src/video/SDL_video.c
  24. 2 6
      src/video/SDL_yuv.c
  25. 4 12
      src/video/kmsdrm/SDL_kmsdrmmouse.c
  26. 2 6
      src/video/kmsdrm/SDL_kmsdrmvideo.c
  27. 6 18
      src/video/kmsdrm/SDL_kmsdrmvulkan.c
  28. 1 3
      src/video/openvr/SDL_openvrvideo.c
  29. 1 4
      src/video/vita/SDL_vitavideo.c
  30. 3 9
      src/video/wayland/SDL_waylanddatamanager.c
  31. 1 3
      src/video/windows/SDL_windowskeyboard.c
  32. 2 6
      src/video/windows/SDL_windowswindow.c
  33. 1 3
      src/video/x11/SDL_x11clipboard.c
  34. 2 6
      src/video/x11/SDL_x11keyboard.c
  35. 1 3
      src/video/x11/SDL_x11messagebox.c
  36. 2 6
      src/video/x11/SDL_x11toolkit.c
  37. 1 3
      test/gamepadutils.c
  38. 2 6
      test/testcontroller.c
  39. 2 6
      test/testffmpeg_vulkan.c
  40. 1 3
      test/testutils.c

+ 2 - 6
src/audio/openslES/SDL_openslES.c

@@ -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!
@@ -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)

+ 2 - 6
src/audio/pipewire/SDL_pipewire.c

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

+ 1 - 3
src/core/linux/SDL_evdev_kbd.c

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

+ 1 - 3
src/core/linux/SDL_ibus.c

@@ -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) {

+ 1 - 3
src/dialog/unix/SDL_zenitymessagebox.c

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

+ 5 - 15
src/dialog/windows/SDL_windowsdialog.c

@@ -731,25 +731,15 @@ quit:
     // default_file_w is a pointer into default_folder_w.
     if (default_folder_w) {
         SDL_free(default_folder_w);
-    } else if (default_file_w) {
-        SDL_free(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++) {

+ 4 - 12
src/gpu/d3d12/SDL_gpu_d3d12.c

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

+ 2 - 6
src/gpu/vulkan/SDL_gpu_vulkan.c

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

+ 1 - 3
src/hidapi/SDL_hidapi.c

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

+ 1 - 3
src/io/SDL_iostream.c

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

+ 1 - 3
src/joystick/SDL_joystick.c

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

+ 2 - 6
src/joystick/hidapi/SDL_hidapi_combined.c

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

+ 5 - 15
src/joystick/hidapi/SDL_hidapi_gip.c

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

+ 2 - 6
src/joystick/linux/SDL_sysjoystick.c

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

+ 4 - 12
src/joystick/windows/SDL_rawinputjoystick.c

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

+ 1 - 3
src/joystick/windows/SDL_windows_gaming_input.c

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

+ 1 - 3
src/render/opengl/SDL_render_gl.c

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

+ 1 - 3
src/render/opengles2/SDL_render_gles2.c

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

+ 1 - 3
src/stdlib/SDL_getenv.c

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

+ 1 - 3
src/test/SDL_test_common.c

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

+ 1 - 3
src/thread/n3ds/SDL_sysmutex.c

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

+ 1 - 3
src/tray/unix/SDL_tray.c

@@ -317,9 +317,7 @@ sdl_dir_error:
     SDL_free(sdl_dir);
 
 tray_error:
-    if (tray) {
-        SDL_free(tray);
-    }
+    SDL_free(tray);
 
     if (gtk) {
         SDL_Gtk_ExitContext(gtk);

+ 1 - 3
src/video/SDL_video.c

@@ -1453,9 +1453,7 @@ void SDL_SetDesktopDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode
 
     SDL_copyp(&last_mode, &display->desktop_mode);
 
-    if (display->desktop_mode.internal) {
-        SDL_free(display->desktop_mode.internal);
-    }
+    SDL_free(display->desktop_mode.internal);
     SDL_copyp(&display->desktop_mode, mode);
     display->desktop_mode.displayID = display->id;
     SDL_FinalizeDisplayMode(&display->desktop_mode);

+ 2 - 6
src/video/SDL_yuv.c

@@ -1557,9 +1557,7 @@ static bool SDL_ConvertPixels_PackUVPlanes_to_NV_std(int width, int height, cons
         dstUV += dstUVPitchLeft;
     }
 
-    if (tmp) {
-        SDL_free(tmp);
-    }
+    SDL_free(tmp);
     return true;
 }
 
@@ -1611,9 +1609,7 @@ static bool SDL_ConvertPixels_SplitNV_to_UVPlanes_std(int width, int height, con
         dst2 += dstUVPitchLeft;
     }
 
-    if (tmp) {
-        SDL_free(tmp);
-    }
+    SDL_free(tmp);
     return true;
 }
 

+ 4 - 12
src/video/kmsdrm/SDL_kmsdrmmouse.c

@@ -243,9 +243,7 @@ static bool KMSDRM_DumpCursorToBO(SDL_VideoDisplay *display, SDL_Mouse *mouse, S
     }
 
 cleanup:
-    if (ready_buffer) {
-        SDL_free(ready_buffer);
-    }
+    SDL_free(ready_buffer);
     return result;
 }
 
@@ -263,9 +261,7 @@ static void KMSDRM_FreeCursor(SDL_Cursor *cursor)
             curdata->buffer = NULL;
         }
         // Free cursor itself
-        if (cursor->internal) {
-            SDL_free(cursor->internal);
-        }
+        SDL_free(cursor->internal);
         SDL_free(cursor);
     }
 }
@@ -322,14 +318,10 @@ static SDL_Cursor *KMSDRM_CreateCursor(SDL_Surface *surface, int hot_x, int hot_
 cleanup:
     if (!result) {
         if (curdata) {
-            if (curdata->buffer) {
-                SDL_free(curdata->buffer);
-            }
+            SDL_free(curdata->buffer);
             SDL_free(curdata);
         }
-        if (cursor) {
-            SDL_free(cursor);
-        }
+        SDL_free(cursor);
     }
 
     return result;

+ 2 - 6
src/video/kmsdrm/SDL_kmsdrmvideo.c

@@ -711,13 +711,9 @@ static SDL_VideoDevice *KMSDRM_CreateDevice(void)
     return device;
 
 cleanup:
-    if (device) {
-        SDL_free(device);
-    }
+    SDL_free(device);
 
-    if (viddata) {
-        SDL_free(viddata);
-    }
+    SDL_free(viddata);
     return NULL;
 }
 

+ 6 - 18
src/video/kmsdrm/SDL_kmsdrmvulkan.c

@@ -443,9 +443,7 @@ bool KMSDRM_Vulkan_CreateSurface(SDL_VideoDevice *_this,
         }
 
         // Free the list of displays supported by this plane.
-        if (supported_displays) {
-            SDL_free(supported_displays);
-        }
+        SDL_free(supported_displays);
 
         // If the display is not supported by this plane, iterate to the next plane.
         if (!plane_supports_display) {
@@ -494,21 +492,11 @@ bool KMSDRM_Vulkan_CreateSurface(SDL_VideoDevice *_this,
     ret = true;  // success!
 
 clean:
-    if (physical_devices) {
-        SDL_free(physical_devices);
-    }
-    if (display_props) {
-        SDL_free(display_props);
-    }
-    if (device_props) {
-        SDL_free(device_props);
-    }
-    if (plane_props) {
-        SDL_free(plane_props);
-    }
-    if (mode_props) {
-        SDL_free(mode_props);
-    }
+    SDL_free(physical_devices);
+    SDL_free(display_props);
+    SDL_free(device_props);
+    SDL_free(plane_props);
+    SDL_free(mode_props);
 
     return ret;
 }

+ 1 - 3
src/video/openvr/SDL_openvrvideo.c

@@ -1141,9 +1141,7 @@ static void OPENVR_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window)
     SDL_WindowData *data;
 
     data = window->internal;
-    if (data) {
-        SDL_free(data);
-    }
+    SDL_free(data);
     window->internal = NULL;
 }
 

+ 1 - 4
src/video/vita/SDL_vitavideo.c

@@ -326,10 +326,7 @@ void VITA_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window)
     SDL_WindowData *data;
 
     data = window->internal;
-    if (data) {
-        // TODO: should we destroy egl context? No one sane should recreate ogl window as non-ogl
-        SDL_free(data);
-    }
+    SDL_free(data);
 
     window->internal = NULL;
     Vita_Window = NULL;

+ 3 - 9
src/video/wayland/SDL_waylanddatamanager.c

@@ -226,9 +226,7 @@ static bool mime_data_list_add(struct wl_list *list,
     }
 
     if (mime_data && buffer && length > 0) {
-        if (mime_data->data) {
-            SDL_free(mime_data->data);
-        }
+        SDL_free(mime_data->data);
         mime_data->data = internal_buffer;
         mime_data->length = length;
     } else {
@@ -244,12 +242,8 @@ static void mime_data_list_free(struct wl_list *list)
     SDL_MimeDataList *next = NULL;
 
     wl_list_for_each_safe (mime_data, next, list, link) {
-        if (mime_data->data) {
-            SDL_free(mime_data->data);
-        }
-        if (mime_data->mime_type) {
-            SDL_free(mime_data->mime_type);
-        }
+        SDL_free(mime_data->data);
+        SDL_free(mime_data->mime_type);
         SDL_free(mime_data);
     }
 }

+ 1 - 3
src/video/windows/SDL_windowskeyboard.c

@@ -815,9 +815,7 @@ static void IME_GetCompositionString(SDL_VideoData *videodata, HIMC himc, DWORD
 
     length = ImmGetCompositionStringW(himc, string, NULL, 0);
     if (length > 0 && videodata->ime_composition_length < length) {
-        if (videodata->ime_composition) {
-            SDL_free(videodata->ime_composition);
-        }
+        SDL_free(videodata->ime_composition);
 
         videodata->ime_composition = (WCHAR *)SDL_malloc(length + sizeof(WCHAR));
         videodata->ime_composition_length = length;

+ 2 - 6
src/video/windows/SDL_windowswindow.c

@@ -589,9 +589,7 @@ static void CleanupWindowData(SDL_VideoDevice *_this, SDL_Window *window)
         if (data->drop_target) {
             WIN_AcceptDragAndDrop(window, false);
         }
-        if (data->ICMFileName) {
-            SDL_free(data->ICMFileName);
-        }
+        SDL_free(data->ICMFileName);
         if (data->keyboard_hook) {
             UnhookWindowsHookEx(data->keyboard_hook);
         }
@@ -1391,9 +1389,7 @@ void WIN_UpdateWindowICCProfile(SDL_Window *window, bool send_event)
                 // fileNameSize includes '\0' on return
                 if (!data->ICMFileName ||
                     SDL_wcscmp(data->ICMFileName, fileName) != 0) {
-                    if (data->ICMFileName) {
-                        SDL_free(data->ICMFileName);
-                    }
+                    SDL_free(data->ICMFileName);
                     data->ICMFileName = SDL_wcsdup(fileName);
                     if (send_event) {
                         SDL_SendWindowEvent(window, SDL_EVENT_WINDOW_ICCPROF_CHANGED, 0, 0);

+ 1 - 3
src/video/x11/SDL_x11clipboard.c

@@ -286,9 +286,7 @@ bool X11_HasClipboardData(SDL_VideoDevice *_this, const char *mime_type)
     size_t length;
     void *data;
     data = X11_GetClipboardData(_this, mime_type, &length);
-    if (data) {
-        SDL_free(data);
-    }
+    SDL_free(data);
     return length > 0;
 }
 

+ 2 - 6
src/video/x11/SDL_x11keyboard.c

@@ -183,13 +183,9 @@ bool X11_InitKeyboard(SDL_VideoDevice *_this)
         (void)setlocale(LC_ALL, prev_locale);
         X11_XSetLocaleModifiers(prev_xmods);
 
-        if (prev_locale) {
-            SDL_free(prev_locale);
-        }
+        SDL_free(prev_locale);
 
-        if (prev_xmods) {
-            SDL_free(prev_xmods);
-        }
+        SDL_free(prev_xmods);
     }
 #endif
     // Try to determine which scancodes are being used based on fingerprint

+ 1 - 3
src/video/x11/SDL_x11messagebox.c

@@ -344,9 +344,7 @@ static bool X11_ShowMessageBoxImpl(const SDL_MessageBoxData *messageboxdata, int
     X11Toolkit_CreateWindowRes(controls.window, w, h, 0, 0, (char *)messageboxdata->title);
     X11Toolkit_DoWindowEventLoop(controls.window);
     X11Toolkit_DestroyWindow(controls.window);
-    if (controls.buttons) {
-        SDL_free(controls.buttons);
-    }
+    SDL_free(controls.buttons);
     return true;
 }
 

+ 2 - 6
src/video/x11/SDL_x11toolkit.c

@@ -1864,12 +1864,8 @@ void X11Toolkit_DestroyWindow(SDL_ToolkitWindowX11 *data) {
             data->controls[i]->func_free(data->controls[i]);
         }
     }
-    if (data->controls) {
-        SDL_free(data->controls);
-    }
-    if (data->dyn_controls) {
-        SDL_free(data->dyn_controls);
-    }
+    SDL_free(data->controls);
+    SDL_free(data->dyn_controls);
 
     if (data->popup_windows) {
         SDL_ListClear(&data->popup_windows);

+ 1 - 3
test/gamepadutils.c

@@ -2642,9 +2642,7 @@ void SetGamepadButtonLabel(GamepadButton *ctx, const char *label)
         return;
     }
 
-    if (ctx->label) {
-        SDL_free(ctx->label);
-    }
+    SDL_free(ctx->label);
 
     ctx->label = SDL_strdup(label);
     ctx->label_width = (float)(FONT_CHARACTER_SIZE * SDL_strlen(label));

+ 2 - 6
test/testcontroller.c

@@ -1237,12 +1237,8 @@ static void DelController(SDL_JoystickID id)
         CyclePS5TriggerEffect(&controllers[i]);
     }
     SDL_assert(controllers[i].gamepad == NULL);
-    if (controllers[i].axis_state) {
-        SDL_free(controllers[i].axis_state);
-    }
-    if (controllers[i].imu_state) {
-        SDL_free(controllers[i].imu_state);
-    }
+    SDL_free(controllers[i].axis_state);
+    SDL_free(controllers[i].imu_state);
     if (controllers[i].joystick) {
         SDL_CloseJoystick(controllers[i].joystick);
     }

+ 2 - 6
test/testffmpeg_vulkan.c

@@ -938,12 +938,8 @@ void DestroyVulkanVideoContext(VulkanVideoContext *context)
         if (context->device) {
             context->vkDeviceWaitIdle(context->device);
         }
-        if (context->instanceExtensions) {
-            SDL_free(context->instanceExtensions);
-        }
-        if (context->deviceExtensions) {
-            SDL_free(context->deviceExtensions);
-        }
+        SDL_free(context->instanceExtensions);
+        SDL_free(context->deviceExtensions);
         if (context->waitSemaphores) {
             for (uint32_t i = 0; i < context->waitSemaphoreCount; ++i) {
                 context->vkDestroySemaphore(context->device, context->waitSemaphores[i], NULL);

+ 1 - 3
test/testutils.c

@@ -123,8 +123,6 @@ SDL_Texture *LoadTexture(SDL_Renderer *renderer, const char *file, bool transpar
         }
     }
     SDL_DestroySurface(temp);
-    if (path) {
-        SDL_free(path);
-    }
+    SDL_free(path);
     return texture;
 }