Fixed Memory/Resource Leaks (#12304)
This commit is contained in:
@@ -72,18 +72,22 @@ static SDL_Cursor *WIN_CreateCursorAndData(HCURSOR hcursor)
|
|||||||
}
|
}
|
||||||
|
|
||||||
SDL_Cursor *cursor = (SDL_Cursor *)SDL_calloc(1, sizeof(*cursor));
|
SDL_Cursor *cursor = (SDL_Cursor *)SDL_calloc(1, sizeof(*cursor));
|
||||||
if (cursor) {
|
if (!cursor) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
SDL_CursorData *data = (SDL_CursorData *)SDL_calloc(1, sizeof(*data));
|
SDL_CursorData *data = (SDL_CursorData *)SDL_calloc(1, sizeof(*data));
|
||||||
if (!data) {
|
if (!data) {
|
||||||
SDL_free(cursor);
|
SDL_free(cursor);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
data->cursor = hcursor;
|
data->cursor = hcursor;
|
||||||
cursor->internal = data;
|
cursor->internal = data;
|
||||||
}
|
|
||||||
return cursor;
|
return cursor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool IsMonochromeSurface(SDL_Surface *surface)
|
static bool IsMonochromeSurface(SDL_Surface *surface)
|
||||||
{
|
{
|
||||||
int x, y;
|
int x, y;
|
||||||
@@ -129,6 +133,9 @@ static HBITMAP CreateColorBitmap(SDL_Surface *surface)
|
|||||||
bitmap = CreateDIBSection(NULL, &bi, DIB_RGB_COLORS, &pixels, NULL, 0);
|
bitmap = CreateDIBSection(NULL, &bi, DIB_RGB_COLORS, &pixels, NULL, 0);
|
||||||
if (!bitmap || !pixels) {
|
if (!bitmap || !pixels) {
|
||||||
WIN_SetError("CreateDIBSection()");
|
WIN_SetError("CreateDIBSection()");
|
||||||
|
if (bitmap) {
|
||||||
|
DeleteObject(bitmap);
|
||||||
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,6 +165,7 @@ static HBITMAP CreateMaskBitmap(SDL_Surface *surface, bool is_monochrome)
|
|||||||
|
|
||||||
pixels = SDL_small_alloc(Uint8, size * (is_monochrome ? 2 : 1), &isstack);
|
pixels = SDL_small_alloc(Uint8, size * (is_monochrome ? 2 : 1), &isstack);
|
||||||
if (!pixels) {
|
if (!pixels) {
|
||||||
|
SDL_OutOfMemory();
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -220,16 +228,20 @@ static HCURSOR WIN_CreateHCursor(SDL_Surface *surface, int hot_x, int hot_y)
|
|||||||
}
|
}
|
||||||
|
|
||||||
hcursor = CreateIconIndirect(&ii);
|
hcursor = CreateIconIndirect(&ii);
|
||||||
|
if (!hcursor) {
|
||||||
|
WIN_SetError("CreateIconIndirect()");
|
||||||
|
DeleteObject(ii.hbmMask);
|
||||||
|
if (ii.hbmColor) {
|
||||||
|
DeleteObject(ii.hbmColor);
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
DeleteObject(ii.hbmMask);
|
DeleteObject(ii.hbmMask);
|
||||||
if (ii.hbmColor) {
|
if (ii.hbmColor) {
|
||||||
DeleteObject(ii.hbmColor);
|
DeleteObject(ii.hbmColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!hcursor) {
|
|
||||||
WIN_SetError("CreateIconIndirect()");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
return hcursor;
|
return hcursor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -359,7 +371,9 @@ static void WIN_FreeCursor(SDL_Cursor *cursor)
|
|||||||
while (data->cache) {
|
while (data->cache) {
|
||||||
CachedCursor *entry = data->cache;
|
CachedCursor *entry = data->cache;
|
||||||
data->cache = entry->next;
|
data->cache = entry->next;
|
||||||
|
if (entry->cursor) {
|
||||||
DestroyCursor(entry->cursor);
|
DestroyCursor(entry->cursor);
|
||||||
|
}
|
||||||
SDL_free(entry);
|
SDL_free(entry);
|
||||||
}
|
}
|
||||||
if (data->cursor) {
|
if (data->cursor) {
|
||||||
@@ -404,6 +418,10 @@ static HCURSOR GetCachedCursor(SDL_Cursor *cursor)
|
|||||||
|
|
||||||
entry = (CachedCursor *)SDL_malloc(sizeof(*entry));
|
entry = (CachedCursor *)SDL_malloc(sizeof(*entry));
|
||||||
if (!entry) {
|
if (!entry) {
|
||||||
|
if (hcursor) {
|
||||||
|
DestroyCursor(hcursor);
|
||||||
|
}
|
||||||
|
SDL_free(entry);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
entry->cursor = hcursor;
|
entry->cursor = hcursor;
|
||||||
|
|||||||
Reference in New Issue
Block a user