error: SDL's allocators now call SDL_OutOfMemory on error.

This means the allocator's caller doesn't need to use SDL_OutOfMemory directly
if the allocation fails.

This applies to the usual allocators: SDL_malloc, SDL_calloc, SDL_realloc
(all of these regardless of if the app supplied a custom allocator or we're
using system malloc() or an internal copy of dlmalloc under the hood),
SDL_aligned_alloc, SDL_small_alloc, SDL_strdup, SDL_asprintf, SDL_wcsdup...
probably others. If it returns something you can pass to SDL_free, it should
work.

The caller might still need to use SDL_OutOfMemory if something that wasn't
SDL allocated the memory: operator new in C++ code, Objective-C's alloc
message, win32 GlobalAlloc, etc.

Fixes #8642.
This commit is contained in:
Ryan C. Gordon
2023-11-30 00:14:27 -05:00
parent 70b65d4170
commit 447b508a77
197 changed files with 313 additions and 742 deletions

View File

@@ -48,7 +48,6 @@ static char *readSymLink(const char *path)
while (1) {
char *ptr = (char *)SDL_realloc(retval, (size_t)len);
if (!ptr) {
SDL_OutOfMemory();
break;
}
@@ -85,7 +84,6 @@ static char *search_path_for_binary(const char *bin)
envr = SDL_strdup(envr);
if (!envr) {
SDL_OutOfMemory();
return NULL;
}
@@ -131,7 +129,6 @@ char *SDL_GetBasePath(void)
if (sysctl(mib, SDL_arraysize(mib), fullpath, &buflen, NULL, 0) != -1) {
retval = SDL_strdup(fullpath);
if (!retval) {
SDL_OutOfMemory();
return NULL;
}
}
@@ -145,14 +142,12 @@ char *SDL_GetBasePath(void)
char *exe, *pwddst;
char *realpathbuf = (char *)SDL_malloc(PATH_MAX + 1);
if (!realpathbuf) {
SDL_OutOfMemory();
return NULL;
}
cmdline = SDL_malloc(len);
if (!cmdline) {
SDL_free(realpathbuf);
SDL_OutOfMemory();
return NULL;
}
@@ -228,7 +223,6 @@ char *SDL_GetBasePath(void)
if ((path) && (path[0] == '/')) { /* must be absolute path... */
retval = SDL_strdup(path);
if (!retval) {
SDL_OutOfMemory();
return NULL;
}
}
@@ -302,7 +296,6 @@ char *SDL_GetPrefPath(const char *org, const char *app)
len += SDL_strlen(append) + SDL_strlen(org) + SDL_strlen(app) + 3;
retval = (char *)SDL_malloc(len);
if (!retval) {
SDL_OutOfMemory();
return NULL;
}
@@ -541,13 +534,7 @@ char *SDL_GetUserFolder(SDL_Folder folder)
return NULL;
}
retval = SDL_strdup(param);
if (!retval) {
SDL_OutOfMemory();
}
return retval;
return SDL_strdup(param);
case SDL_FOLDER_DESKTOP:
param = "DESKTOP";