From 38537aa82a1fb21412cc89967770a246641a887e Mon Sep 17 00:00:00 2001 From: skyleo Date: Sat, 27 Jan 2024 19:53:52 +0100 Subject: [PATCH 1/2] Fix memory leaks caused by overwriting pointer to previously allocated emblem_data without freeing first --- src/map/guild.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/map/guild.c b/src/map/guild.c index 4769cd3213d..3fd7c4c44c6 100644 --- a/src/map/guild.c +++ b/src/map/guild.c @@ -691,6 +691,8 @@ static int guild_recv_info(const struct guild *sg, struct fifo_chunk_buf *emblem g->emblem_data = NULL; g->emblem_len = 0; } else { + if (!guild_new) + aFree(before.emblem_data); g->emblem_data = aMalloc(emblem_buf->data_size); memcpy(g->emblem_data, emblem_buf->data, emblem_buf->data_size); } From ad7b9e8639f9e9e6d3c13ee0cfed72ed573a12b5 Mon Sep 17 00:00:00 2001 From: skyleo Date: Sat, 27 Jan 2024 20:00:56 +0100 Subject: [PATCH 2/2] Fix memory leaks caused by not freeing emblem_data when removing one guild from dbmap --- src/char/int_guild.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/char/int_guild.c b/src/char/int_guild.c index 5339c6443c9..353d594b688 100644 --- a/src/char/int_guild.c +++ b/src/char/int_guild.c @@ -89,6 +89,7 @@ static int inter_guild_save_timer(int tid, int64 tick, int id, intptr_t data) // Nothing to save, guild is ready for removal. if (chr->show_save_log) ShowInfo("Guild Unloaded (%d - %s)\n", g->guild_id, g->name); + aFree(g->emblem_data); db_remove(inter_guild->guild_db, key); } } @@ -1207,6 +1208,7 @@ static bool inter_guild_disband(int guild_id) inter->log("guild %s (id=%d) broken\n", g->name, guild_id); //Remove the guild from memory. [Skotlex] + aFree(g->emblem_data); idb_remove(inter_guild->guild_db, guild_id); return true;