Skip to content

Commit

Permalink
Don't call the property cleanup function if setting the property fails
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Dec 4, 2023
1 parent 14380ec commit 6cfce10
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/SDL_properties.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ static SDL_PropertiesID SDL_last_properties_id;
static SDL_PropertiesID SDL_global_properties;


static void SDL_FreeProperty(const void *key, const void *value, void *data)
static void SDL_FreePropertyWithCleanup(const void *key, const void *value, void *data, SDL_bool cleanup)
{
SDL_Property *property = (SDL_Property *)value;
if (property) {
switch (property->type) {
case SDL_PROPERTY_TYPE_POINTER:
if (property->cleanup) {
if (property->cleanup && cleanup) {
property->cleanup(property->userdata, property->value.pointer_value);
}
break;
Expand All @@ -78,6 +78,11 @@ static void SDL_FreeProperty(const void *key, const void *value, void *data)
SDL_free((void *)value);
}

static void SDL_FreeProperty(const void *key, const void *value, void *data)
{
SDL_FreePropertyWithCleanup(key, value, data, SDL_TRUE);
}

static void SDL_FreeProperties(const void *key, const void *value, void *data)
{
SDL_Properties *properties = (SDL_Properties *)value;
Expand Down Expand Up @@ -228,11 +233,11 @@ static int SDL_PrivateSetProperty(SDL_PropertiesID props, const char *name, SDL_
int result = 0;

if (!props) {
SDL_FreeProperty(NULL, property, NULL);
SDL_FreePropertyWithCleanup(NULL, property, NULL, SDL_FALSE);
return SDL_InvalidParamError("props");
}
if (!name || !*name) {
SDL_FreeProperty(NULL, property, NULL);
SDL_FreePropertyWithCleanup(NULL, property, NULL, SDL_FALSE);
return SDL_InvalidParamError("name");
}

Expand All @@ -241,7 +246,7 @@ static int SDL_PrivateSetProperty(SDL_PropertiesID props, const char *name, SDL_
SDL_UnlockMutex(SDL_properties_lock);

if (!properties) {
SDL_FreeProperty(NULL, property, NULL);
SDL_FreePropertyWithCleanup(NULL, property, NULL, SDL_FALSE);
return SDL_InvalidParamError("props");
}

Expand All @@ -251,7 +256,7 @@ static int SDL_PrivateSetProperty(SDL_PropertiesID props, const char *name, SDL_
if (property) {
char *key = SDL_strdup(name);
if (!SDL_InsertIntoHashTable(properties->props, key, property)) {
SDL_FreeProperty(key, property, NULL);
SDL_FreePropertyWithCleanup(key, property, NULL, SDL_FALSE);
result = -1;
}
}
Expand Down

0 comments on commit 6cfce10

Please sign in to comment.