From 87ae1a73123439812579eb67154d44c3589ea1f3 Mon Sep 17 00:00:00 2001 From: veclavtalica Date: Mon, 13 Jan 2025 18:09:06 +0300 Subject: [PATCH] missing textures: fix double free --- src/twn_textures.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/twn_textures.c b/src/twn_textures.c index 4b618dd..88e4f73 100644 --- a/src/twn_textures.c +++ b/src/twn_textures.c @@ -68,12 +68,11 @@ static SDL_Surface *gen_missing_texture_surface(void) { } /* same data is reused after being allocated/generated once */ - SDL_Surface* surface = SDL_CreateRGBSurfaceFrom(missing_texture_data, 64, 64, - 3 * 8, - 64 * 3, - rmask, gmask, bmask, 0); - - return surface; + SDL_Surface *missing_texture_surface = SDL_CreateRGBSurfaceFrom(missing_texture_data, 64, 64, + 3 * 8, + 64 * 3, + rmask, gmask, bmask, 0); + return missing_texture_surface; } @@ -328,7 +327,8 @@ void textures_cache_deinit(TextureCache *cache) { /* free cache hashes */ for (size_t i = 0; i < shlenu(cache->hash); ++i) { - stbi_image_free(cache->hash[i].value.data->pixels); + if (cache->hash[i].value.data->pixels != missing_texture_data) + stbi_image_free(cache->hash[i].value.data->pixels); SDL_FreeSurface(cache->hash[i].value.data); } shfree(cache->hash);