From a7269bbe8a6a01a178f31e2bf1f4a4cde78cec1b Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Sat, 26 Apr 2025 19:41:51 +0200 Subject: [PATCH] game-strings: fix memory leak --- src/libtrx/game/game_string_table/common.c | 8 ++++---- src/libtrx/game/game_string_table/priv.c | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/libtrx/game/game_string_table/common.c b/src/libtrx/game/game_string_table/common.c index f44260c6c..3d31c1738 100644 --- a/src/libtrx/game/game_string_table/common.c +++ b/src/libtrx/game/game_string_table/common.c @@ -137,7 +137,7 @@ void GameStringTable_Apply(const GF_LEVEL *const level) Object_ResetNames(); ASSERT(m_GST_Layers != nullptr); for (int32_t i = 0; i < m_GST_Layers->count; i++) { - const GS_FILE *const gs_file = Vector_Get(m_GST_Layers, i); + const GS_FILE *const gs_file = *(GS_FILE **)Vector_Get(m_GST_Layers, i); M_ApplyLayer(level, gs_file); } M_DoObjectAliases(); @@ -145,14 +145,14 @@ void GameStringTable_Apply(const GF_LEVEL *const level) void GameStringTable_Init(void) { - m_GST_Layers = Vector_Create(sizeof(GS_FILE)); + m_GST_Layers = Vector_Create(sizeof(GS_FILE *)); } void GameStringTable_Shutdown(void) { if (m_GST_Layers != nullptr) { for (int32_t i = 0; i < m_GST_Layers->count; i++) { - GS_FILE *const gs_file = Vector_Get(m_GST_Layers, i); + GS_FILE *const gs_file = *(GS_FILE **)Vector_Get(m_GST_Layers, i); GS_File_Free(gs_file); } Vector_Free(m_GST_Layers); @@ -168,6 +168,6 @@ void GameStringTable_Load(const char *const path, const bool load_levels) } GS_FILE *gs_file = GS_File_CreateFromString(data, load_levels); ASSERT(m_GST_Layers != nullptr); - Vector_Add(m_GST_Layers, gs_file); + Vector_Add(m_GST_Layers, &gs_file); Memory_FreePointer(&data); } diff --git a/src/libtrx/game/game_string_table/priv.c b/src/libtrx/game/game_string_table/priv.c index 0b62cc41b..a9bada043 100644 --- a/src/libtrx/game/game_string_table/priv.c +++ b/src/libtrx/game/game_string_table/priv.c @@ -52,4 +52,5 @@ void GS_File_Free(GS_FILE *const gs_file) for (int32_t i = 0; i < GFLT_NUMBER_OF; i++) { M_FreeLevelsTable(&gs_file->level_tables[i]); } + Memory_Free(gs_file); }