From bba2a5d360b6f7788032a203c97c9e07178032d3 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sat, 10 Feb 2024 08:04:27 -0800 Subject: [PATCH] Added SDL_SetFreeableProperty() for internal use --- src/SDL_properties.c | 10 ++++++++++ src/SDL_properties_c.h | 1 + 2 files changed, 11 insertions(+) diff --git a/src/SDL_properties.c b/src/SDL_properties.c index 566ea51ba9..5ac9478e39 100644 --- a/src/SDL_properties.c +++ b/src/SDL_properties.c @@ -375,6 +375,16 @@ int SDL_SetProperty(SDL_PropertiesID props, const char *name, void *value) return SDL_PrivateSetProperty(props, name, property); } +static void CleanupFreeableProperty(void *userdata, void *value) +{ + SDL_free(value); +} + +int SDL_SetFreeableProperty(SDL_PropertiesID props, const char *name, void *value) +{ + return SDL_SetPropertyWithCleanup(props, name, value, CleanupFreeableProperty, NULL); +} + static void CleanupSurface(void *userdata, void *value) { SDL_Surface *surface = (SDL_Surface *)value; diff --git a/src/SDL_properties_c.h b/src/SDL_properties_c.h index ee23ae8e8b..d996fa12f7 100644 --- a/src/SDL_properties_c.h +++ b/src/SDL_properties_c.h @@ -20,5 +20,6 @@ */ extern int SDL_InitProperties(void); +extern int SDL_SetFreeableProperty(SDL_PropertiesID props, const char *name, void *value); extern int SDL_SetSurfaceProperty(SDL_PropertiesID props, const char *name, SDL_Surface *surface); extern void SDL_QuitProperties(void);