mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-05-11 14:38:24 +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
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user