mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-05-29 16:09:13 +00:00
remove most of SDL_OutOfMemory() calls where SDL is the allocator.
Since commit 447b508a77
, SDL_malloc,
SDL_calloc, and SDL_realloc already calls SDL_OutOfMemory().
This commit is contained in:
parent
7abc589438
commit
e909c0360f
15 changed files with 21 additions and 57 deletions
|
@ -1335,8 +1335,6 @@ static SDL_AudioDeviceID *GetAudioDevices(int *count, SDL_bool iscapture)
|
||||||
|
|
||||||
SDL_assert(devs_seen == num_devices);
|
SDL_assert(devs_seen == num_devices);
|
||||||
retval[devs_seen] = 0; // null-terminated.
|
retval[devs_seen] = 0; // null-terminated.
|
||||||
} else {
|
|
||||||
SDL_OutOfMemory();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SDL_UnlockRWLock(current_audio.device_hash_lock);
|
SDL_UnlockRWLock(current_audio.device_hash_lock);
|
||||||
|
|
|
@ -126,7 +126,7 @@ static int ReserveMemoryPoolBlocks(SDL_MemoryPool *pool, size_t num_blocks)
|
||||||
void *block = AllocNewMemoryPoolBlock(pool);
|
void *block = AllocNewMemoryPoolBlock(pool);
|
||||||
|
|
||||||
if (block == NULL) {
|
if (block == NULL) {
|
||||||
return SDL_OutOfMemory();
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
*(void **)block = pool->free_blocks;
|
*(void **)block = pool->free_blocks;
|
||||||
|
|
|
@ -44,7 +44,7 @@ static int EMSCRIPTENCAMERA_AcquireFrame(SDL_CameraDevice *device, SDL_Surface *
|
||||||
{
|
{
|
||||||
void *rgba = SDL_malloc(device->actual_spec.width * device->actual_spec.height * 4);
|
void *rgba = SDL_malloc(device->actual_spec.width * device->actual_spec.height * 4);
|
||||||
if (!rgba) {
|
if (!rgba) {
|
||||||
return SDL_OutOfMemory();
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
*timestampNS = SDL_GetTicksNS(); // best we can do here.
|
*timestampNS = SDL_GetTicksNS(); // best we can do here.
|
||||||
|
|
|
@ -2855,7 +2855,6 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeFileDialog)(
|
||||||
char **charFileList = SDL_calloc(sizeof(char*), count + 1);
|
char **charFileList = SDL_calloc(sizeof(char*), count + 1);
|
||||||
|
|
||||||
if (charFileList == NULL) {
|
if (charFileList == NULL) {
|
||||||
SDL_OutOfMemory();
|
|
||||||
mAndroidFileDialogData.callback(mAndroidFileDialogData.userdata, NULL, -1);
|
mAndroidFileDialogData.callback(mAndroidFileDialogData.userdata, NULL, -1);
|
||||||
mAndroidFileDialogData.callback = NULL;
|
mAndroidFileDialogData.callback = NULL;
|
||||||
return;
|
return;
|
||||||
|
@ -2879,7 +2878,6 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeFileDialog)(
|
||||||
if (!newFile) {
|
if (!newFile) {
|
||||||
(*env)->ReleaseStringUTFChars(env, string, utf8string);
|
(*env)->ReleaseStringUTFChars(env, string, utf8string);
|
||||||
(*env)->DeleteLocalRef(env, string);
|
(*env)->DeleteLocalRef(env, string);
|
||||||
SDL_OutOfMemory();
|
|
||||||
mAndroidFileDialogData.callback(mAndroidFileDialogData.userdata, NULL, -1);
|
mAndroidFileDialogData.callback(mAndroidFileDialogData.userdata, NULL, -1);
|
||||||
mAndroidFileDialogData.callback = NULL;
|
mAndroidFileDialogData.callback = NULL;
|
||||||
|
|
||||||
|
|
|
@ -87,7 +87,6 @@ void show_file_dialog(cocoa_FileDialogType type, SDL_DialogFileCallback callback
|
||||||
char *pattern_ptr = pattern;
|
char *pattern_ptr = pattern;
|
||||||
|
|
||||||
if (!pattern_ptr) {
|
if (!pattern_ptr) {
|
||||||
SDL_OutOfMemory();
|
|
||||||
callback(userdata, NULL, -1);
|
callback(userdata, NULL, -1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,7 +86,6 @@ static void DBus_AppendFilter(SDL_DBusContext *dbus, DBusMessageIter *parent, co
|
||||||
|
|
||||||
patterns = SDL_strdup(filter->pattern);
|
patterns = SDL_strdup(filter->pattern);
|
||||||
if (!patterns) {
|
if (!patterns) {
|
||||||
SDL_OutOfMemory();
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,7 +98,6 @@ static void DBus_AppendFilter(SDL_DBusContext *dbus, DBusMessageIter *parent, co
|
||||||
|
|
||||||
glob_pattern = SDL_calloc(sizeof(char), max_len);
|
glob_pattern = SDL_calloc(sizeof(char), max_len);
|
||||||
if (!glob_pattern) {
|
if (!glob_pattern) {
|
||||||
SDL_OutOfMemory();
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
glob_pattern[0] = '*';
|
glob_pattern[0] = '*';
|
||||||
|
@ -222,7 +220,6 @@ static DBusHandlerResult DBus_MessageFilter(DBusConnection *conn, DBusMessage *m
|
||||||
|
|
||||||
path = SDL_malloc(sizeof(const char *) * length);
|
path = SDL_malloc(sizeof(const char *) * length);
|
||||||
if (!path) {
|
if (!path) {
|
||||||
SDL_OutOfMemory();
|
|
||||||
signal_data->callback(signal_data->userdata, NULL, -1);
|
signal_data->callback(signal_data->userdata, NULL, -1);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
@ -233,7 +230,6 @@ static DBusHandlerResult DBus_MessageFilter(DBusConnection *conn, DBusMessage *m
|
||||||
++length;
|
++length;
|
||||||
path = SDL_realloc(path, sizeof(const char *) * length);
|
path = SDL_realloc(path, sizeof(const char *) * length);
|
||||||
if (!path) {
|
if (!path) {
|
||||||
SDL_OutOfMemory();
|
|
||||||
signal_data->callback(signal_data->userdata, NULL, -1);
|
signal_data->callback(signal_data->userdata, NULL, -1);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,7 +54,6 @@ typedef struct
|
||||||
#define CHECK_OOM() \
|
#define CHECK_OOM() \
|
||||||
{ \
|
{ \
|
||||||
if (!argv[nextarg - 1]) { \
|
if (!argv[nextarg - 1]) { \
|
||||||
SDL_OutOfMemory(); \
|
|
||||||
CLEAR_AND_RETURN() \
|
CLEAR_AND_RETURN() \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
|
@ -120,9 +119,7 @@ static char** generate_args(const zenityArgs* info)
|
||||||
}
|
}
|
||||||
|
|
||||||
argv = SDL_malloc(sizeof(char *) * argc + 1);
|
argv = SDL_malloc(sizeof(char *) * argc + 1);
|
||||||
|
|
||||||
if (!argv) {
|
if (!argv) {
|
||||||
SDL_OutOfMemory();
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -259,7 +256,6 @@ static void run_zenity(zenityArgs* arg_struct)
|
||||||
while ((bytes_last_read = read(out[0], readbuffer, sizeof(readbuffer)))) {
|
while ((bytes_last_read = read(out[0], readbuffer, sizeof(readbuffer)))) {
|
||||||
char *new_container = SDL_realloc(container, bytes_read + bytes_last_read);
|
char *new_container = SDL_realloc(container, bytes_read + bytes_last_read);
|
||||||
if (!new_container) {
|
if (!new_container) {
|
||||||
SDL_OutOfMemory();
|
|
||||||
SDL_free(container);
|
SDL_free(container);
|
||||||
close(out[0]);
|
close(out[0]);
|
||||||
callback(userdata, NULL, -1);
|
callback(userdata, NULL, -1);
|
||||||
|
@ -286,7 +282,6 @@ static void run_zenity(zenityArgs* arg_struct)
|
||||||
char **array = (char **) SDL_malloc((narray + 1) * sizeof(char *));
|
char **array = (char **) SDL_malloc((narray + 1) * sizeof(char *));
|
||||||
|
|
||||||
if (!array) {
|
if (!array) {
|
||||||
SDL_OutOfMemory();
|
|
||||||
SDL_free(container);
|
SDL_free(container);
|
||||||
callback(userdata, NULL, -1);
|
callback(userdata, NULL, -1);
|
||||||
return;
|
return;
|
||||||
|
@ -304,7 +299,6 @@ static void run_zenity(zenityArgs* arg_struct)
|
||||||
narray++;
|
narray++;
|
||||||
char **new_array = (char **) SDL_realloc(array, (narray + 1) * sizeof(char *));
|
char **new_array = (char **) SDL_realloc(array, (narray + 1) * sizeof(char *));
|
||||||
if (!new_array) {
|
if (!new_array) {
|
||||||
SDL_OutOfMemory();
|
|
||||||
SDL_free(container);
|
SDL_free(container);
|
||||||
SDL_free(array);
|
SDL_free(array);
|
||||||
callback(userdata, NULL, -1);
|
callback(userdata, NULL, -1);
|
||||||
|
@ -343,7 +337,6 @@ void SDL_Zenity_ShowOpenFileDialog(SDL_DialogFileCallback callback, void* userda
|
||||||
|
|
||||||
args = SDL_malloc(sizeof(*args));
|
args = SDL_malloc(sizeof(*args));
|
||||||
if (!args) {
|
if (!args) {
|
||||||
SDL_OutOfMemory();
|
|
||||||
callback(userdata, NULL, -1);
|
callback(userdata, NULL, -1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -371,7 +364,6 @@ void SDL_Zenity_ShowSaveFileDialog(SDL_DialogFileCallback callback, void* userda
|
||||||
|
|
||||||
args = SDL_malloc(sizeof(zenityArgs));
|
args = SDL_malloc(sizeof(zenityArgs));
|
||||||
if (args == NULL) {
|
if (args == NULL) {
|
||||||
SDL_OutOfMemory();
|
|
||||||
callback(userdata, NULL, -1);
|
callback(userdata, NULL, -1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -399,7 +391,6 @@ void SDL_Zenity_ShowOpenFolderDialog(SDL_DialogFileCallback callback, void* user
|
||||||
|
|
||||||
args = SDL_malloc(sizeof(zenityArgs));
|
args = SDL_malloc(sizeof(zenityArgs));
|
||||||
if (args == NULL) {
|
if (args == NULL) {
|
||||||
SDL_OutOfMemory();
|
|
||||||
callback(userdata, NULL, -1);
|
callback(userdata, NULL, -1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -369,29 +369,22 @@ int windows_file_dialog_thread(void* ptr)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CALLBACK browse_callback_proc(
|
int CALLBACK browse_callback_proc(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData)
|
||||||
HWND hwnd,
|
|
||||||
UINT uMsg,
|
|
||||||
LPARAM lParam,
|
|
||||||
LPARAM lpData)
|
|
||||||
{
|
{
|
||||||
|
switch (uMsg) {
|
||||||
switch (uMsg)
|
case BFFM_INITIALIZED:
|
||||||
{
|
if (lpData) {
|
||||||
case BFFM_INITIALIZED :
|
SendMessage(hwnd, BFFM_SETSELECTION, TRUE, lpData);
|
||||||
if(lpData)
|
|
||||||
{
|
|
||||||
SendMessage(hwnd, BFFM_SETSELECTION, TRUE, lpData);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case BFFM_SELCHANGED :
|
case BFFM_SELCHANGED:
|
||||||
break;
|
break;
|
||||||
case BFFM_VALIDATEFAILED :
|
case BFFM_VALIDATEFAILED:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void windows_ShowFolderDialog(void* ptr)
|
void windows_ShowFolderDialog(void* ptr)
|
||||||
|
@ -400,7 +393,6 @@ void windows_ShowFolderDialog(void* ptr)
|
||||||
SDL_Window *window = args->parent;
|
SDL_Window *window = args->parent;
|
||||||
SDL_DialogFileCallback callback = args->callback;
|
SDL_DialogFileCallback callback = args->callback;
|
||||||
void *userdata = args->userdata;
|
void *userdata = args->userdata;
|
||||||
|
|
||||||
HWND parent = NULL;
|
HWND parent = NULL;
|
||||||
|
|
||||||
if (window) {
|
if (window) {
|
||||||
|
|
|
@ -109,13 +109,13 @@ static int GAMEINPUT_InternalAddOrFind(IGameInputDevice *pDevice)
|
||||||
|
|
||||||
elem = (GAMEINPUT_InternalDevice *)SDL_calloc(1, sizeof(*elem));
|
elem = (GAMEINPUT_InternalDevice *)SDL_calloc(1, sizeof(*elem));
|
||||||
if (!elem) {
|
if (!elem) {
|
||||||
return SDL_OutOfMemory();
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
devicelist = (GAMEINPUT_InternalDevice **)SDL_realloc(g_GameInputList.devices, sizeof(elem) * (g_GameInputList.count + 1LL));
|
devicelist = (GAMEINPUT_InternalDevice **)SDL_realloc(g_GameInputList.devices, sizeof(elem) * (g_GameInputList.count + 1LL));
|
||||||
if (!devicelist) {
|
if (!devicelist) {
|
||||||
SDL_free(elem);
|
SDL_free(elem);
|
||||||
return SDL_OutOfMemory();
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Generate a device path */
|
/* Generate a device path */
|
||||||
|
@ -264,7 +264,7 @@ static int GAMEINPUT_JoystickGetCount(void)
|
||||||
|
|
||||||
static void GAMEINPUT_JoystickDetect(void)
|
static void GAMEINPUT_JoystickDetect(void)
|
||||||
{
|
{
|
||||||
int idx = 0;
|
int idx;
|
||||||
GAMEINPUT_InternalDevice *elem = NULL;
|
GAMEINPUT_InternalDevice *elem = NULL;
|
||||||
|
|
||||||
for (idx = 0; idx < g_GameInputList.count; ++idx) {
|
for (idx = 0; idx < g_GameInputList.count; ++idx) {
|
||||||
|
@ -396,7 +396,7 @@ static int GAMEINPUT_JoystickOpen(SDL_Joystick *joystick, int device_index)
|
||||||
|
|
||||||
hwdata = (GAMEINPUT_InternalJoystickHwdata *)SDL_calloc(1, sizeof(*hwdata));
|
hwdata = (GAMEINPUT_InternalJoystickHwdata *)SDL_calloc(1, sizeof(*hwdata));
|
||||||
if (!hwdata) {
|
if (!hwdata) {
|
||||||
return SDL_OutOfMemory();
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
hwdata->devref = elem;
|
hwdata->devref = elem;
|
||||||
|
|
|
@ -184,7 +184,6 @@ static SDL_bool HIDAPI_DriverSteamDeck_InitDevice(SDL_HIDAPI_Device *device)
|
||||||
|
|
||||||
ctx = (SDL_DriverSteamDeck_Context *)SDL_calloc(1, sizeof(*ctx));
|
ctx = (SDL_DriverSteamDeck_Context *)SDL_calloc(1, sizeof(*ctx));
|
||||||
if (ctx == NULL) {
|
if (ctx == NULL) {
|
||||||
SDL_OutOfMemory();
|
|
||||||
return SDL_FALSE;
|
return SDL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -151,7 +151,6 @@ static SDL_Storage *STEAM_User_Create(const char *org, const char *app, SDL_Prop
|
||||||
|
|
||||||
steam = (STEAM_RemoteStorage*) SDL_malloc(sizeof(STEAM_RemoteStorage));
|
steam = (STEAM_RemoteStorage*) SDL_malloc(sizeof(STEAM_RemoteStorage));
|
||||||
if (steam == NULL) {
|
if (steam == NULL) {
|
||||||
SDL_OutOfMemory();
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -76,7 +76,6 @@ char *SDLTest_GenerateRunSeed(const int length)
|
||||||
seed = (char *)SDL_malloc((length + 1) * sizeof(char));
|
seed = (char *)SDL_malloc((length + 1) * sizeof(char));
|
||||||
if (!seed) {
|
if (!seed) {
|
||||||
SDLTest_LogError("SDL_malloc for run seed output buffer failed.");
|
SDLTest_LogError("SDL_malloc for run seed output buffer failed.");
|
||||||
SDL_OutOfMemory();
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,7 +150,6 @@ static Uint64 SDLTest_GenerateExecKey(const char *runSeed, const char *suiteName
|
||||||
buffer = (char *)SDL_malloc(entireStringLength);
|
buffer = (char *)SDL_malloc(entireStringLength);
|
||||||
if (!buffer) {
|
if (!buffer) {
|
||||||
SDLTest_LogError("Failed to allocate buffer for execKey generation.");
|
SDLTest_LogError("Failed to allocate buffer for execKey generation.");
|
||||||
SDL_OutOfMemory();
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
(void)SDL_snprintf(buffer, entireStringLength, "%s%s%s%d", runSeed, suiteName, testName, iteration);
|
(void)SDL_snprintf(buffer, entireStringLength, "%s%s%s%d", runSeed, suiteName, testName, iteration);
|
||||||
|
@ -457,7 +455,6 @@ int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], const char *user
|
||||||
failedTests = (const SDLTest_TestCaseReference **)SDL_malloc(totalNumberOfTests * sizeof(SDLTest_TestCaseReference *));
|
failedTests = (const SDLTest_TestCaseReference **)SDL_malloc(totalNumberOfTests * sizeof(SDLTest_TestCaseReference *));
|
||||||
if (!failedTests) {
|
if (!failedTests) {
|
||||||
SDLTest_LogError("Unable to allocate cache for failed tests");
|
SDLTest_LogError("Unable to allocate cache for failed tests");
|
||||||
SDL_OutOfMemory();
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,7 +60,6 @@ int SDL_SetTLS(SDL_TLSID id, const void *value, void(SDLCALL *destructor)(void *
|
||||||
newlimit = (id + TLS_ALLOC_CHUNKSIZE);
|
newlimit = (id + TLS_ALLOC_CHUNKSIZE);
|
||||||
new_storage = (SDL_TLSData *)SDL_realloc(storage, sizeof(*storage) + (newlimit - 1) * sizeof(storage->array[0]));
|
new_storage = (SDL_TLSData *)SDL_realloc(storage, sizeof(*storage) + (newlimit - 1) * sizeof(storage->array[0]));
|
||||||
if (!new_storage) {
|
if (!new_storage) {
|
||||||
SDL_OutOfMemory();
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
storage = new_storage;
|
storage = new_storage;
|
||||||
|
|
|
@ -85,7 +85,6 @@ static SDL_VideoDevice *N3DS_CreateDevice(void)
|
||||||
/* Initialize internal data */
|
/* Initialize internal data */
|
||||||
phdata = (SDL_VideoData *)SDL_calloc(1, sizeof(SDL_VideoData));
|
phdata = (SDL_VideoData *)SDL_calloc(1, sizeof(SDL_VideoData));
|
||||||
if (!phdata) {
|
if (!phdata) {
|
||||||
SDL_OutOfMemory();
|
|
||||||
SDL_free(device);
|
SDL_free(device);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,7 +75,6 @@ static SDL_Cursor *X11_CreateDefaultCursor(void)
|
||||||
/* None is used to indicate the default cursor */
|
/* None is used to indicate the default cursor */
|
||||||
cursor->driverdata = (void *)(uintptr_t)None;
|
cursor->driverdata = (void *)(uintptr_t)None;
|
||||||
}
|
}
|
||||||
|
|
||||||
return cursor;
|
return cursor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -263,9 +262,7 @@ static SDL_Cursor *X11_CreateSystemCursor(SDL_SystemCursor id)
|
||||||
|
|
||||||
if (x11_cursor != None) {
|
if (x11_cursor != None) {
|
||||||
cursor = SDL_calloc(1, sizeof(*cursor));
|
cursor = SDL_calloc(1, sizeof(*cursor));
|
||||||
if (!cursor) {
|
if (cursor) {
|
||||||
SDL_OutOfMemory();
|
|
||||||
} else {
|
|
||||||
cursor->driverdata = (void *)(uintptr_t)x11_cursor;
|
cursor->driverdata = (void *)(uintptr_t)x11_cursor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue