From 2e8b7fa585b2e97ace9e4c28c507d0b05e41313a Mon Sep 17 00:00:00 2001 From: backwardsEric Date: Mon, 11 Nov 2019 15:50:11 -0800 Subject: [PATCH 1/3] Plugged memory leak of quest information when player structure reset. --- src/player-birth.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/player-birth.c b/src/player-birth.c index 5af363b7..1cc629f0 100644 --- a/src/player-birth.c +++ b/src/player-birth.c @@ -401,6 +401,9 @@ void player_init(struct player *p) mem_free(p->obj_k->curses); mem_free(p->obj_k); } + if (p->quests) { + player_quests_free(p); + } /* Wipe the player */ memset(p, 0, sizeof(struct player)); -- 2.21.0 (Apple Git-122.2) From d721e3e6ec6b02b2c38a8fcc96eb8c2b924889d9 Mon Sep 17 00:00:00 2001 From: backwardsEric Date: Mon, 11 Nov 2019 15:52:53 -0800 Subject: [PATCH 2/3] Plugged memory leaks of the character background information when that information is changed or reset. --- src/player-birth.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/player-birth.c b/src/player-birth.c index 1cc629f0..15396e9f 100644 --- a/src/player-birth.c +++ b/src/player-birth.c @@ -158,6 +158,9 @@ static void save_roller_data(birther *tosave) for (i = 0; i < STAT_MAX; i++) tosave->stat[i] = player->stat_birth[i]; + if (tosave->history) { + string_free(tosave->history); + } tosave->history = player->history; player->history = NULL; my_strcpy(tosave->name, player->full_name, sizeof(tosave->name)); @@ -203,12 +206,19 @@ static void load_roller_data(birther *saved, birther *prev_player) } /* Load previous history */ - player->history = saved->history; + if (player->history) { + string_free(player->history); + } + player->history = string_make(saved->history); my_strcpy(player->full_name, saved->name, sizeof(player->full_name)); /* Save the current data if the caller is interested in it. */ - if (prev_player) + if (prev_player) { + if (prev_player->history) { + string_free(prev_player->history); + } *prev_player = temp; + } } @@ -401,6 +411,9 @@ void player_init(struct player *p) mem_free(p->obj_k->curses); mem_free(p->obj_k); } + if (p->history) { + string_free(p->history); + } if (p->quests) { player_quests_free(p); } @@ -904,8 +917,12 @@ void player_generate(struct player *p, const struct player_race *r, /* Roll for age/height/weight */ get_ahw(p); - if (!old_history) + if (!old_history) { + if (player->history) { + string_free(player->history); + } p->history = get_history(p->race->history); + } } -- 2.21.0 (Apple Git-122.2) From 6496df9b8ec3a2f48af70036ea41a5bed0ab8bb5 Mon Sep 17 00:00:00 2001 From: backwardsEric Date: Mon, 11 Nov 2019 15:54:16 -0800 Subject: [PATCH 3/3] Plugged memory leak when the character background information is edited by the player. --- src/ui-birth.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ui-birth.c b/src/ui-birth.c index a5198ece..8578e392 100644 --- a/src/ui-birth.c +++ b/src/ui-birth.c @@ -1026,6 +1026,8 @@ int edit_text(char *buffer, int buflen) { } } + mem_free(line_starts); + mem_free(line_lengths); textblock_free(tb); } -- 2.21.0 (Apple Git-122.2)