mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-10-05 09:26:25 +00:00
Fix property cleanup callback not being called on error (#9663)
The documentation for `SDL_SetPropertyWithCleanup` mentions that the cleanup function is called upon failure. But this wasn't working in the code.
This commit is contained in:
@@ -305,11 +305,11 @@ static int SDL_PrivateSetProperty(SDL_PropertiesID props, const char *name, SDL_
|
|||||||
int result = 0;
|
int result = 0;
|
||||||
|
|
||||||
if (!props) {
|
if (!props) {
|
||||||
SDL_FreePropertyWithCleanup(NULL, property, NULL, SDL_FALSE);
|
SDL_FreePropertyWithCleanup(NULL, property, NULL, SDL_TRUE);
|
||||||
return SDL_InvalidParamError("props");
|
return SDL_InvalidParamError("props");
|
||||||
}
|
}
|
||||||
if (!name || !*name) {
|
if (!name || !*name) {
|
||||||
SDL_FreePropertyWithCleanup(NULL, property, NULL, SDL_FALSE);
|
SDL_FreePropertyWithCleanup(NULL, property, NULL, SDL_TRUE);
|
||||||
return SDL_InvalidParamError("name");
|
return SDL_InvalidParamError("name");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -318,7 +318,7 @@ static int SDL_PrivateSetProperty(SDL_PropertiesID props, const char *name, SDL_
|
|||||||
SDL_UnlockMutex(SDL_properties_lock);
|
SDL_UnlockMutex(SDL_properties_lock);
|
||||||
|
|
||||||
if (!properties) {
|
if (!properties) {
|
||||||
SDL_FreePropertyWithCleanup(NULL, property, NULL, SDL_FALSE);
|
SDL_FreePropertyWithCleanup(NULL, property, NULL, SDL_TRUE);
|
||||||
return SDL_InvalidParamError("props");
|
return SDL_InvalidParamError("props");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -328,7 +328,7 @@ static int SDL_PrivateSetProperty(SDL_PropertiesID props, const char *name, SDL_
|
|||||||
if (property) {
|
if (property) {
|
||||||
char *key = SDL_strdup(name);
|
char *key = SDL_strdup(name);
|
||||||
if (!SDL_InsertIntoHashTable(properties->props, key, property)) {
|
if (!SDL_InsertIntoHashTable(properties->props, key, property)) {
|
||||||
SDL_FreePropertyWithCleanup(key, property, NULL, SDL_FALSE);
|
SDL_FreePropertyWithCleanup(key, property, NULL, SDL_TRUE);
|
||||||
result = -1;
|
result = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -343,11 +343,17 @@ int SDL_SetPropertyWithCleanup(SDL_PropertiesID props, const char *name, void *v
|
|||||||
SDL_Property *property;
|
SDL_Property *property;
|
||||||
|
|
||||||
if (!value) {
|
if (!value) {
|
||||||
|
if (cleanup) {
|
||||||
|
cleanup(userdata, value);
|
||||||
|
}
|
||||||
return SDL_ClearProperty(props, name);
|
return SDL_ClearProperty(props, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
property = (SDL_Property *)SDL_calloc(1, sizeof(*property));
|
property = (SDL_Property *)SDL_calloc(1, sizeof(*property));
|
||||||
if (!property) {
|
if (!property) {
|
||||||
|
if (cleanup) {
|
||||||
|
cleanup(userdata, value);
|
||||||
|
}
|
||||||
SDL_FreePropertyWithCleanup(NULL, property, NULL, SDL_FALSE);
|
SDL_FreePropertyWithCleanup(NULL, property, NULL, SDL_FALSE);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@@ -274,7 +274,6 @@ static int MEDIAFOUNDATION_AcquireFrame(SDL_CameraDevice *device, SDL_Surface *f
|
|||||||
frame->pixels = pixels;
|
frame->pixels = pixels;
|
||||||
frame->pitch = (int) pitch;
|
frame->pitch = (int) pitch;
|
||||||
if (SDL_SetPropertyWithCleanup(surfprops, PROP_SURFACE_IMFOBJS_POINTER, objs, CleanupIMF2DBuffer2, NULL) == -1) {
|
if (SDL_SetPropertyWithCleanup(surfprops, PROP_SURFACE_IMFOBJS_POINTER, objs, CleanupIMF2DBuffer2, NULL) == -1) {
|
||||||
CleanupIMF2DBuffer2(NULL, objs);
|
|
||||||
retval = -1;
|
retval = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -287,7 +286,6 @@ static int MEDIAFOUNDATION_AcquireFrame(SDL_CameraDevice *device, SDL_Surface *f
|
|||||||
frame->pixels = pixels;
|
frame->pixels = pixels;
|
||||||
frame->pitch = (int) pitch;
|
frame->pitch = (int) pitch;
|
||||||
if (SDL_SetPropertyWithCleanup(surfprops, PROP_SURFACE_IMFOBJS_POINTER, objs, CleanupIMF2DBuffer, NULL) == -1) {
|
if (SDL_SetPropertyWithCleanup(surfprops, PROP_SURFACE_IMFOBJS_POINTER, objs, CleanupIMF2DBuffer, NULL) == -1) {
|
||||||
CleanupIMF2DBuffer(NULL, objs);
|
|
||||||
retval = -1;
|
retval = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -305,7 +303,6 @@ static int MEDIAFOUNDATION_AcquireFrame(SDL_CameraDevice *device, SDL_Surface *f
|
|||||||
frame->pixels = pixels;
|
frame->pixels = pixels;
|
||||||
frame->pitch = (int) pitch;
|
frame->pitch = (int) pitch;
|
||||||
if (SDL_SetPropertyWithCleanup(surfprops, PROP_SURFACE_IMFOBJS_POINTER, objs, CleanupIMFMediaBuffer, NULL) == -1) {
|
if (SDL_SetPropertyWithCleanup(surfprops, PROP_SURFACE_IMFOBJS_POINTER, objs, CleanupIMFMediaBuffer, NULL) == -1) {
|
||||||
CleanupIMFMediaBuffer(NULL, objs);
|
|
||||||
retval = -1;
|
retval = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -321,7 +321,10 @@ static int SDL_CreateWindowTexture(SDL_VideoDevice *_this, SDL_Window *window, S
|
|||||||
SDL_DestroyRenderer(renderer);
|
SDL_DestroyRenderer(renderer);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
SDL_SetPropertyWithCleanup(props, SDL_PROP_WINDOW_TEXTUREDATA_POINTER, data, SDL_CleanupWindowTextureData, NULL);
|
if (SDL_SetPropertyWithCleanup(props, SDL_PROP_WINDOW_TEXTUREDATA_POINTER, data, SDL_CleanupWindowTextureData, NULL) < 0) {
|
||||||
|
SDL_DestroyRenderer(renderer);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
data->renderer = renderer;
|
data->renderer = renderer;
|
||||||
}
|
}
|
||||||
|
@@ -293,7 +293,7 @@ static int properties_testCleanup(void *arg)
|
|||||||
SDLTest_AssertPass("Call to SDL_SetProperty(cleanup)");
|
SDLTest_AssertPass("Call to SDL_SetProperty(cleanup)");
|
||||||
count = 0;
|
count = 0;
|
||||||
SDL_SetPropertyWithCleanup(props, "a", "0", cleanup, &count);
|
SDL_SetPropertyWithCleanup(props, "a", "0", cleanup, &count);
|
||||||
SDL_SetPropertyWithCleanup(props, "a", NULL, cleanup, &count);
|
SDL_ClearProperty(props, "a");
|
||||||
SDLTest_AssertCheck(count == 1,
|
SDLTest_AssertCheck(count == 1,
|
||||||
"Verify cleanup for deleting property, got %d, expected 1", count);
|
"Verify cleanup for deleting property, got %d, expected 1", count);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user