From b262b0ebc90d0555ec5efdb1990fe7c494296e88 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Mon, 22 Oct 2018 20:50:32 -0400 Subject: [PATCH] Small stack allocations fall back to malloc if they're unexpectedly large. --- src/SDL_assert.c | 1 + src/SDL_internal.h | 4 ++++ src/SDL_log.c | 8 ++++--- src/core/android/SDL_android.c | 5 +++-- src/file/SDL_rwops.c | 1 + src/joystick/SDL_gamecontroller.c | 5 +++-- src/joystick/SDL_joystick.c | 5 +++-- src/loadso/dlopen/SDL_sysloadso.c | 5 +++-- src/main/windows/SDL_windows_main.c | 10 +++++---- src/render/SDL_render.c | 25 +++++++++++++--------- src/render/opengl/SDL_render_gl.c | 5 +++-- src/render/opengl/SDL_shaders_gl.c | 5 +++-- src/render/opengles/SDL_render_gles.c | 5 +++-- src/render/opengles2/SDL_render_gles2.c | 10 +++++---- src/video/cocoa/SDL_cocoamodes.m | 7 +++--- src/video/windows/SDL_windowsevents.c | 13 ++++++----- src/video/windows/SDL_windowsframebuffer.c | 5 +++-- src/video/windows/SDL_windowsmouse.c | 5 +++-- src/video/windows/SDL_windowswindow.c | 12 ++++++----- 19 files changed, 84 insertions(+), 52 deletions(-) diff --git a/src/SDL_assert.c b/src/SDL_assert.c index 1ca083ad4c98a..5a9556d4ecf81 100644 --- a/src/SDL_assert.c +++ b/src/SDL_assert.c @@ -178,6 +178,7 @@ SDL_PromptAssertion(const SDL_assert_data *data, void *userdata) (void) userdata; /* unused in default handler. */ + /* !!! FIXME: why is this using SDL_stack_alloc and not just "char message[SDL_MAX_LOG_MESSAGE];" ? */ message = SDL_stack_alloc(char, SDL_MAX_LOG_MESSAGE); if (!message) { /* Uh oh, we're in real trouble now... */ diff --git a/src/SDL_internal.h b/src/SDL_internal.h index e0ba2a82c30f6..f8215bf34a731 100644 --- a/src/SDL_internal.h +++ b/src/SDL_internal.h @@ -35,6 +35,10 @@ #define SDL_VARIABLE_LENGTH_ARRAY #endif +#define SDL_MAX_SMALL_ALLOC_STACKSIZE 128 +#define SDL_small_alloc(type, count, pisstack) ( (*(pisstack) = ((sizeof(type)*(count)) < SDL_MAX_SMALL_ALLOC_STACKSIZE)), (*(pisstack) ? SDL_stack_alloc(type, count) : (type*)SDL_malloc(sizeof(type)*(count))) ) +#define SDL_small_free(ptr, isstack) if ((isstack)) { SDL_stack_free(ptr); } else { SDL_free(ptr); } + #include "dynapi/SDL_dynapi.h" #if SDL_DYNAMIC_API diff --git a/src/SDL_log.c b/src/SDL_log.c index b1bf27d7a1954..b89f7ee3a8b11 100644 --- a/src/SDL_log.c +++ b/src/SDL_log.c @@ -282,6 +282,7 @@ SDL_LogMessageV(int category, SDL_LogPriority priority, const char *fmt, va_list return; } + /* !!! FIXME: why not just "char message[SDL_MAX_LOG_MESSAGE];" ? */ message = SDL_stack_alloc(char, SDL_MAX_LOG_MESSAGE); if (!message) { return; @@ -321,6 +322,7 @@ SDL_LogOutput(void *userdata, int category, SDL_LogPriority priority, char *output; size_t length; LPTSTR tstr; + SDL_bool isstack; #if !defined(HAVE_STDIO_H) && !defined(__WINRT__) BOOL attachResult; @@ -364,7 +366,7 @@ SDL_LogOutput(void *userdata, int category, SDL_LogPriority priority, #endif /* !defined(HAVE_STDIO_H) && !defined(__WINRT__) */ length = SDL_strlen(SDL_priority_prefixes[priority]) + 2 + SDL_strlen(message) + 1 + 1 + 1; - output = SDL_stack_alloc(char, length); + output = SDL_small_alloc(char, length, &isstack); SDL_snprintf(output, length, "%s: %s\r\n", SDL_priority_prefixes[priority], message); tstr = WIN_UTF8ToString(output); @@ -389,7 +391,7 @@ SDL_LogOutput(void *userdata, int category, SDL_LogPriority priority, #endif /* !defined(HAVE_STDIO_H) && !defined(__WINRT__) */ SDL_free(tstr); - SDL_stack_free(output); + SDL_small_free(output, isstack); } #elif defined(__ANDROID__) { @@ -404,7 +406,7 @@ SDL_LogOutput(void *userdata, int category, SDL_LogPriority priority, extern void SDL_NSLog(const char *text); { char *text; - + /* !!! FIXME: why not just "char text[SDL_MAX_LOG_MESSAGE];" ? */ text = SDL_stack_alloc(char, SDL_MAX_LOG_MESSAGE); if (text) { SDL_snprintf(text, SDL_MAX_LOG_MESSAGE, "%s: %s", SDL_priority_prefixes[priority], message); diff --git a/src/core/android/SDL_android.c b/src/core/android/SDL_android.c index 91786042de321..81ccd4a96c218 100644 --- a/src/core/android/SDL_android.c +++ b/src/core/android/SDL_android.c @@ -466,10 +466,11 @@ JNIEXPORT int JNICALL SDL_JAVA_INTERFACE(nativeRunMain)(JNIEnv* env, jclass cls, int argc; int len; char **argv; + SDL_bool isstack; /* Prepare the arguments. */ len = (*env)->GetArrayLength(env, array); - argv = SDL_stack_alloc(char*, 1 + len + 1); + argv = SDL_small_alloc(char*, 1 + len + 1, &isstack); /* !!! FIXME: check for NULL */ argc = 0; /* Use the name "app_process" so PHYSFS_platformCalcBaseDir() works. https://bitbucket.org/MartinFelis/love-android-sdl2/issue/23/release-build-crash-on-start @@ -502,7 +503,7 @@ JNIEXPORT int JNICALL SDL_JAVA_INTERFACE(nativeRunMain)(JNIEnv* env, jclass cls, for (i = 0; i < argc; ++i) { SDL_free(argv[i]); } - SDL_stack_free(argv); + SDL_small_free(argv, isstack); } else { __android_log_print(ANDROID_LOG_ERROR, "SDL", "nativeRunMain(): Couldn't find function %s in library %s", function_name, library_file); diff --git a/src/file/SDL_rwops.c b/src/file/SDL_rwops.c index cf5d3aa0b9784..5b0969d56ff47 100644 --- a/src/file/SDL_rwops.c +++ b/src/file/SDL_rwops.c @@ -528,6 +528,7 @@ SDL_RWFromFile(const char *file, const char *mode) char *path; FILE *fp; + /* !!! FIXME: why not just "char path[PATH_MAX];" ? */ path = SDL_stack_alloc(char, PATH_MAX); if (path) { SDL_snprintf(path, PATH_MAX, "%s/%s", diff --git a/src/joystick/SDL_gamecontroller.c b/src/joystick/SDL_gamecontroller.c index fa647819c4147..41100a4130e5b 100644 --- a/src/joystick/SDL_gamecontroller.c +++ b/src/joystick/SDL_gamecontroller.c @@ -203,13 +203,14 @@ static void UpdateEventsForDeviceRemoval() { int i, num_events; SDL_Event *events; + SDL_bool isstack; num_events = SDL_PeepEvents(NULL, 0, SDL_PEEKEVENT, SDL_CONTROLLERDEVICEADDED, SDL_CONTROLLERDEVICEADDED); if (num_events <= 0) { return; } - events = SDL_stack_alloc(SDL_Event, num_events); + events = SDL_small_alloc(SDL_Event, num_events, &isstack); if (!events) { return; } @@ -220,7 +221,7 @@ static void UpdateEventsForDeviceRemoval() } SDL_PeepEvents(events, num_events, SDL_ADDEVENT, 0, 0); - SDL_stack_free(events); + SDL_small_free(events, isstack); } static SDL_bool HasSameOutput(SDL_ExtendedGameControllerBind *a, SDL_ExtendedGameControllerBind *b) diff --git a/src/joystick/SDL_joystick.c b/src/joystick/SDL_joystick.c index 72c5656d2655c..9d22122a48191 100644 --- a/src/joystick/SDL_joystick.c +++ b/src/joystick/SDL_joystick.c @@ -752,13 +752,14 @@ static void UpdateEventsForDeviceRemoval() { int i, num_events; SDL_Event *events; + SDL_bool isstack; num_events = SDL_PeepEvents(NULL, 0, SDL_PEEKEVENT, SDL_JOYDEVICEADDED, SDL_JOYDEVICEADDED); if (num_events <= 0) { return; } - events = SDL_stack_alloc(SDL_Event, num_events); + events = SDL_small_alloc(SDL_Event, num_events, &isstack); if (!events) { return; } @@ -769,7 +770,7 @@ static void UpdateEventsForDeviceRemoval() } SDL_PeepEvents(events, num_events, SDL_ADDEVENT, 0, 0); - SDL_stack_free(events); + SDL_small_free(events, isstack); } void SDL_PrivateJoystickRemoved(SDL_JoystickID device_instance) diff --git a/src/loadso/dlopen/SDL_sysloadso.c b/src/loadso/dlopen/SDL_sysloadso.c index 18b4b843693cc..ed89a211d7bbd 100644 --- a/src/loadso/dlopen/SDL_sysloadso.c +++ b/src/loadso/dlopen/SDL_sysloadso.c @@ -61,12 +61,13 @@ SDL_LoadFunction(void *handle, const char *name) void *symbol = dlsym(handle, name); if (symbol == NULL) { /* append an underscore for platforms that need that. */ + SDL_bool isstack; size_t len = 1 + SDL_strlen(name) + 1; - char *_name = SDL_stack_alloc(char, len); + char *_name = SDL_small_alloc(char, len, &isstack); _name[0] = '_'; SDL_strlcpy(&_name[1], name, len); symbol = dlsym(handle, _name); - SDL_stack_free(_name); + SDL_small_free(_name, isstack); if (symbol == NULL) { SDL_SetError("Failed loading %s: %s", name, (const char *) dlerror()); diff --git a/src/main/windows/SDL_windows_main.c b/src/main/windows/SDL_windows_main.c index 5e643a44b5427..212a6a3e25260 100644 --- a/src/main/windows/SDL_windows_main.c +++ b/src/main/windows/SDL_windows_main.c @@ -131,6 +131,7 @@ main_utf8(int argc, char *argv[]) static int main_getcmdline() { + SDL_bool isstack; char **argv; int argc; char *cmdline; @@ -150,7 +151,7 @@ main_getcmdline() /* Parse it into argv and argc */ argc = ParseCommandLine(cmdline, NULL); - argv = SDL_stack_alloc(char *, argc + 1); + argv = SDL_small_alloc(char *, argc + 1, &isstack); if (argv == NULL) { return OutOfMemory(); } @@ -158,7 +159,7 @@ main_getcmdline() retval = main_utf8(argc, argv); - SDL_stack_free(argv); + SDL_small_free(argv, isstack); SDL_free(cmdline); return retval; @@ -177,8 +178,9 @@ console_ansi_main(int argc, char *argv[]) int console_wmain(int argc, wchar_t *wargv[], wchar_t *wenvp) { + SDL_bool isstack; int retval = 0; - char **argv = SDL_stack_alloc(char*, argc + 1); + char **argv = SDL_small_alloc(char*, argc + 1, &isstack); int i; for (i = 0; i < argc; ++i) { @@ -189,7 +191,7 @@ console_wmain(int argc, wchar_t *wargv[], wchar_t *wenvp) retval = main_utf8(argc, argv); /* !!! FIXME: we are leaking all the elements of argv we allocated. */ - SDL_stack_free(argv); + SDL_small_free(argv, isstack); return retval; } diff --git a/src/render/SDL_render.c b/src/render/SDL_render.c index 5bbcd790bd98e..b03524b4c5259 100644 --- a/src/render/SDL_render.c +++ b/src/render/SDL_render.c @@ -2176,8 +2176,9 @@ RenderDrawPointsWithRects(SDL_Renderer * renderer, SDL_FRect *frects; int i; int retval = -1; + SDL_bool isstack; - frects = SDL_stack_alloc(SDL_FRect, count); + frects = SDL_small_alloc(SDL_FRect, count, &isstack); if (!frects) { return SDL_OutOfMemory(); } @@ -2190,7 +2191,7 @@ RenderDrawPointsWithRects(SDL_Renderer * renderer, retval = QueueCmdFillRects(renderer, frects, count); - SDL_stack_free(frects); + SDL_small_free(frects, isstack); return retval < 0 ? retval : FlushRenderCommandsIfNotBatching(renderer); } @@ -2202,6 +2203,7 @@ SDL_RenderDrawPoints(SDL_Renderer * renderer, SDL_FPoint *fpoints; int i; int retval; + SDL_bool isstack; CHECK_RENDERER_MAGIC(renderer, -1); @@ -2221,7 +2223,7 @@ SDL_RenderDrawPoints(SDL_Renderer * renderer, return RenderDrawPointsWithRects(renderer, points, count); } - fpoints = SDL_stack_alloc(SDL_FPoint, count); + fpoints = SDL_small_alloc(SDL_FPoint, count, &isstack); if (!fpoints) { return SDL_OutOfMemory(); } @@ -2232,7 +2234,7 @@ SDL_RenderDrawPoints(SDL_Renderer * renderer, retval = QueueCmdDrawPoints(renderer, fpoints, count); - SDL_stack_free(fpoints); + SDL_small_free(fpoints, isstack); return retval < 0 ? retval : FlushRenderCommandsIfNotBatching(renderer); } @@ -2258,8 +2260,9 @@ RenderDrawLinesWithRects(SDL_Renderer * renderer, SDL_FPoint fpoints[2]; int i, nrects = 0; int retval = 0; + SDL_bool isstack; - frects = SDL_stack_alloc(SDL_FRect, count-1); + frects = SDL_small_alloc(SDL_FRect, count-1, &isstack); if (!frects) { return SDL_OutOfMemory(); } @@ -2295,7 +2298,7 @@ RenderDrawLinesWithRects(SDL_Renderer * renderer, retval += QueueCmdFillRects(renderer, frects, nrects); - SDL_stack_free(frects); + SDL_small_free(frects, isstack); if (retval < 0) { retval = -1; @@ -2310,6 +2313,7 @@ SDL_RenderDrawLines(SDL_Renderer * renderer, SDL_FPoint *fpoints; int i; int retval; + SDL_bool isstack; CHECK_RENDERER_MAGIC(renderer, -1); @@ -2329,7 +2333,7 @@ SDL_RenderDrawLines(SDL_Renderer * renderer, return RenderDrawLinesWithRects(renderer, points, count); } - fpoints = SDL_stack_alloc(SDL_FPoint, count); + fpoints = SDL_small_alloc(SDL_FPoint, count, &isstack); if (!fpoints) { return SDL_OutOfMemory(); } @@ -2340,7 +2344,7 @@ SDL_RenderDrawLines(SDL_Renderer * renderer, retval = QueueCmdDrawLines(renderer, fpoints, count); - SDL_stack_free(fpoints); + SDL_small_free(fpoints, isstack); return retval < 0 ? retval : FlushRenderCommandsIfNotBatching(renderer); } @@ -2426,6 +2430,7 @@ SDL_RenderFillRects(SDL_Renderer * renderer, SDL_FRect *frects; int i; int retval; + SDL_bool isstack; CHECK_RENDERER_MAGIC(renderer, -1); @@ -2441,7 +2446,7 @@ SDL_RenderFillRects(SDL_Renderer * renderer, return 0; } - frects = SDL_stack_alloc(SDL_FRect, count); + frects = SDL_small_alloc(SDL_FRect, count, &isstack); if (!frects) { return SDL_OutOfMemory(); } @@ -2454,7 +2459,7 @@ SDL_RenderFillRects(SDL_Renderer * renderer, retval = QueueCmdFillRects(renderer, frects, count); - SDL_stack_free(frects); + SDL_small_free(frects, isstack); return retval < 0 ? retval : FlushRenderCommandsIfNotBatching(renderer); } diff --git a/src/render/opengl/SDL_render_gl.c b/src/render/opengl/SDL_render_gl.c index ef8507ebf2bb2..7d0f08d71c7db 100644 --- a/src/render/opengl/SDL_render_gl.c +++ b/src/render/opengl/SDL_render_gl.c @@ -1348,10 +1348,11 @@ GL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, /* Flip the rows to be top-down if necessary */ if (!renderer->target) { + SDL_bool isstack; length = rect->w * SDL_BYTESPERPIXEL(temp_format); src = (Uint8*)temp_pixels + (rect->h-1)*temp_pitch; dst = (Uint8*)temp_pixels; - tmp = SDL_stack_alloc(Uint8, length); + tmp = SDL_small_alloc(Uint8, length, &isstack); rows = rect->h / 2; while (rows--) { SDL_memcpy(tmp, dst, length); @@ -1360,7 +1361,7 @@ GL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, dst += temp_pitch; src -= temp_pitch; } - SDL_stack_free(tmp); + SDL_small_free(tmp, isstack); } status = SDL_ConvertPixels(rect->w, rect->h, diff --git a/src/render/opengl/SDL_shaders_gl.c b/src/render/opengl/SDL_shaders_gl.c index 251b54d130f56..650b24463902f 100644 --- a/src/render/opengl/SDL_shaders_gl.c +++ b/src/render/opengl/SDL_shaders_gl.c @@ -340,11 +340,12 @@ CompileShader(GL_ShaderContext *ctx, GLhandleARB shader, const char *defines, co ctx->glCompileShaderARB(shader); ctx->glGetObjectParameterivARB(shader, GL_OBJECT_COMPILE_STATUS_ARB, &status); if (status == 0) { + SDL_bool isstack; GLint length; char *info; ctx->glGetObjectParameterivARB(shader, GL_OBJECT_INFO_LOG_LENGTH_ARB, &length); - info = SDL_stack_alloc(char, length+1); + info = SDL_small_alloc(char, length+1, &isstack); ctx->glGetInfoLogARB(shader, length, NULL, info); SDL_LogError(SDL_LOG_CATEGORY_RENDER, "Failed to compile shader:\n%s%s\n%s", defines, source, info); @@ -352,7 +353,7 @@ CompileShader(GL_ShaderContext *ctx, GLhandleARB shader, const char *defines, co fprintf(stderr, "Failed to compile shader:\n%s%s\n%s", defines, source, info); #endif - SDL_stack_free(info); + SDL_small_free(info, isstack); return SDL_FALSE; } else { diff --git a/src/render/opengles/SDL_render_gles.c b/src/render/opengles/SDL_render_gles.c index 6f662afa9cf82..a410152e7be20 100644 --- a/src/render/opengles/SDL_render_gles.c +++ b/src/render/opengles/SDL_render_gles.c @@ -972,10 +972,11 @@ GLES_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, /* Flip the rows to be top-down if necessary */ if (!renderer->target) { + SDL_bool isstack; length = rect->w * SDL_BYTESPERPIXEL(temp_format); src = (Uint8*)temp_pixels + (rect->h-1)*temp_pitch; dst = (Uint8*)temp_pixels; - tmp = SDL_stack_alloc(Uint8, length); + tmp = SDL_small_alloc(Uint8, length, &isstack); rows = rect->h / 2; while (rows--) { SDL_memcpy(tmp, dst, length); @@ -984,7 +985,7 @@ GLES_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, dst += temp_pitch; src -= temp_pitch; } - SDL_stack_free(tmp); + SDL_small_free(tmp, isstack); } status = SDL_ConvertPixels(rect->w, rect->h, diff --git a/src/render/opengles2/SDL_render_gles2.c b/src/render/opengles2/SDL_render_gles2.c index 97d1d4461b7b8..c6c9f80f641a9 100644 --- a/src/render/opengles2/SDL_render_gles2.c +++ b/src/render/opengles2/SDL_render_gles2.c @@ -601,19 +601,20 @@ GLES2_CacheShader(GLES2_RenderData *data, GLES2_ShaderType type) compileSuccessful = GL_TRUE; } if (!compileSuccessful) { + SDL_bool isstack = SDL_FALSE; char *info = NULL; int length = 0; data->glGetShaderiv(entry->id, GL_INFO_LOG_LENGTH, &length); if (length > 0) { - info = SDL_stack_alloc(char, length); + info = SDL_small_alloc(char, length, &isstack); if (info) { data->glGetShaderInfoLog(entry->id, length, &length, info); } } if (info) { SDL_SetError("Failed to load the shader: %s", info); - SDL_stack_free(info); + SDL_small_free(info, isstack); } else { SDL_SetError("Failed to load the shader"); } @@ -1814,10 +1815,11 @@ GLES2_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, /* Flip the rows to be top-down if necessary */ if (!renderer->target) { + SDL_bool isstack; length = rect->w * SDL_BYTESPERPIXEL(temp_format); src = (Uint8*)temp_pixels + (rect->h-1)*temp_pitch; dst = (Uint8*)temp_pixels; - tmp = SDL_stack_alloc(Uint8, length); + tmp = SDL_small_alloc(Uint8, length, &isstack); rows = rect->h / 2; while (rows--) { SDL_memcpy(tmp, dst, length); @@ -1826,7 +1828,7 @@ GLES2_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, dst += temp_pitch; src -= temp_pitch; } - SDL_stack_free(tmp); + SDL_small_free(tmp, isstack); } status = SDL_ConvertPixels(rect->w, rect->h, diff --git a/src/video/cocoa/SDL_cocoamodes.m b/src/video/cocoa/SDL_cocoamodes.m index 97ccd945dcf20..b614b795b1178 100644 --- a/src/video/cocoa/SDL_cocoamodes.m +++ b/src/video/cocoa/SDL_cocoamodes.m @@ -187,6 +187,7 @@ CGDisplayErr result; CGDirectDisplayID *displays; CGDisplayCount numDisplays; + SDL_bool isstack; int pass, i; result = CGGetOnlineDisplayList(0, NULL, &numDisplays); @@ -194,11 +195,11 @@ CG_SetError("CGGetOnlineDisplayList()", result); return; } - displays = SDL_stack_alloc(CGDirectDisplayID, numDisplays); + displays = SDL_small_alloc(CGDirectDisplayID, numDisplays, &isstack); result = CGGetOnlineDisplayList(numDisplays, displays, &numDisplays); if (result != kCGErrorSuccess) { CG_SetError("CGGetOnlineDisplayList()", result); - SDL_stack_free(displays); + SDL_small_free(displays, isstack); return; } @@ -260,7 +261,7 @@ SDL_free(display.name); } } - SDL_stack_free(displays); + SDL_small_free(displays, isstack); }} int diff --git a/src/video/windows/SDL_windowsevents.c b/src/video/windows/SDL_windowsevents.c index 5773f39953f7f..6505b89b78fd6 100644 --- a/src/video/windows/SDL_windowsevents.c +++ b/src/video/windows/SDL_windowsevents.c @@ -901,7 +901,8 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) case WM_TOUCH: if (data->videodata->GetTouchInputInfo && data->videodata->CloseTouchInputHandle) { UINT i, num_inputs = LOWORD(wParam); - PTOUCHINPUT inputs = SDL_stack_alloc(TOUCHINPUT, num_inputs); + SDL_bool isstack; + PTOUCHINPUT inputs = SDL_small_alloc(TOUCHINPUT, num_inputs, &isstack); if (data->videodata->GetTouchInputInfo((HTOUCHINPUT)lParam, num_inputs, inputs, sizeof(TOUCHINPUT))) { RECT rect; float x, y; @@ -909,7 +910,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) if (!GetClientRect(hwnd, &rect) || (rect.right == rect.left && rect.bottom == rect.top)) { if (inputs) { - SDL_stack_free(inputs); + SDL_small_free(inputs, isstack); } break; } @@ -943,7 +944,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) } } } - SDL_stack_free(inputs); + SDL_small_free(inputs, isstack); data->videodata->CloseTouchInputHandle((HTOUCHINPUT)lParam); return 0; @@ -954,17 +955,19 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { UINT i; HDROP drop = (HDROP) wParam; + SDL_bool isstack; UINT count = DragQueryFile(drop, 0xFFFFFFFF, NULL, 0); for (i = 0; i < count; ++i) { + SDL_bool isstack; UINT size = DragQueryFile(drop, i, NULL, 0) + 1; - LPTSTR buffer = SDL_stack_alloc(TCHAR, size); + LPTSTR buffer = SDL_small_alloc(TCHAR, size, &isstack); if (buffer) { if (DragQueryFile(drop, i, buffer, size)) { char *file = WIN_StringToUTF8(buffer); SDL_SendDropFile(data->window, file); SDL_free(file); } - SDL_stack_free(buffer); + SDL_small_free(buffer, isstack); } } SDL_SendDropComplete(data->window); diff --git a/src/video/windows/SDL_windowsframebuffer.c b/src/video/windows/SDL_windowsframebuffer.c index e07d9c43130b0..f884f7fa0dd8b 100644 --- a/src/video/windows/SDL_windowsframebuffer.c +++ b/src/video/windows/SDL_windowsframebuffer.c @@ -27,6 +27,7 @@ int WIN_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch) { SDL_WindowData *data = (SDL_WindowData *) window->driverdata; + SDL_bool isstack; size_t size; LPBITMAPINFO info; HBITMAP hbm; @@ -41,7 +42,7 @@ int WIN_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, voi /* Find out the format of the screen */ size = sizeof(BITMAPINFOHEADER) + 256 * sizeof (RGBQUAD); - info = (LPBITMAPINFO)SDL_stack_alloc(Uint8, size); + info = (LPBITMAPINFO)SDL_small_alloc(Uint8, size, &isstack); if (!info) { return SDL_OutOfMemory(); } @@ -85,7 +86,7 @@ int WIN_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, voi data->mdc = CreateCompatibleDC(data->hdc); data->hbm = CreateDIBSection(data->hdc, info, DIB_RGB_COLORS, pixels, NULL, 0); - SDL_stack_free(info); + SDL_small_free(info, isstack); if (!data->hbm) { return WIN_SetError("Unable to create DIB"); diff --git a/src/video/windows/SDL_windowsmouse.c b/src/video/windows/SDL_windowsmouse.c index 1ddeae24beabd..a8abc48c32d2b 100644 --- a/src/video/windows/SDL_windowsmouse.c +++ b/src/video/windows/SDL_windowsmouse.c @@ -97,6 +97,7 @@ WIN_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y) LPVOID pixels; LPVOID maskbits; size_t maskbitslen; + SDL_bool isstack; ICONINFO ii; SDL_zero(bmh); @@ -112,7 +113,7 @@ WIN_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y) bmh.bV4BlueMask = 0x000000FF; maskbitslen = ((surface->w + (pad - (surface->w % pad))) / 8) * surface->h; - maskbits = SDL_stack_alloc(Uint8,maskbitslen); + maskbits = SDL_small_alloc(Uint8,maskbitslen); if (maskbits == NULL) { SDL_OutOfMemory(); return NULL; @@ -129,7 +130,7 @@ WIN_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y) ii.hbmColor = CreateDIBSection(hdc, (BITMAPINFO*)&bmh, DIB_RGB_COLORS, &pixels, NULL, 0); ii.hbmMask = CreateBitmap(surface->w, surface->h, 1, 1, maskbits); ReleaseDC(NULL, hdc); - SDL_stack_free(maskbits); + SDL_small_free(maskbits, isstack); SDL_assert(surface->format->format == SDL_PIXELFORMAT_ARGB8888); SDL_assert(surface->pitch == surface->w * 4); diff --git a/src/video/windows/SDL_windowswindow.c b/src/video/windows/SDL_windowswindow.c index ba5ef0583905e..e6ce7633be704 100644 --- a/src/video/windows/SDL_windowswindow.c +++ b/src/video/windows/SDL_windowswindow.c @@ -380,10 +380,11 @@ WIN_CreateWindowFrom(_THIS, SDL_Window * window, const void *data) HWND hwnd = (HWND) data; LPTSTR title; int titleLen; + SDL_bool isstack; /* Query the title from the existing window */ titleLen = GetWindowTextLength(hwnd); - title = SDL_stack_alloc(TCHAR, titleLen + 1); + title = SDL_small_alloc(TCHAR, titleLen + 1, &isstack); if (title) { titleLen = GetWindowText(hwnd, title, titleLen); } else { @@ -393,7 +394,7 @@ WIN_CreateWindowFrom(_THIS, SDL_Window * window, const void *data) window->title = WIN_StringToUTF8(title); } if (title) { - SDL_stack_free(title); + SDL_small_free(title, isstack); } if (SetupWindowData(_this, window, hwnd, GetParent(hwnd), SDL_FALSE) < 0) { @@ -443,14 +444,15 @@ WIN_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon) BYTE *icon_bmp; int icon_len, mask_len, y; SDL_RWops *dst; + SDL_bool isstack; /* Create temporary buffer for ICONIMAGE structure */ mask_len = (icon->h * (icon->w + 7)/8); icon_len = 40 + icon->h * icon->w * sizeof(Uint32) + mask_len; - icon_bmp = SDL_stack_alloc(BYTE, icon_len); + icon_bmp = SDL_small_alloc(BYTE, icon_len, &isstack); dst = SDL_RWFromMem(icon_bmp, icon_len); if (!dst) { - SDL_stack_free(icon_bmp); + SDL_small_free(icon_bmp, isstack); return; } @@ -481,7 +483,7 @@ WIN_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon) hicon = CreateIconFromResource(icon_bmp, icon_len, TRUE, 0x00030000); SDL_RWclose(dst); - SDL_stack_free(icon_bmp); + SDL_small_free(icon_bmp, isstack); /* Set the icon for the window */ SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM) hicon);