release wish history memory

The memory leak only happened at end of game so wasn't a big deal.
This commit is contained in:
PatR
2026-03-25 15:54:44 -07:00
parent d939238ea6
commit f49ac037f9
3 changed files with 18 additions and 1 deletions

View File

@@ -3989,6 +3989,7 @@ extern char *item_what(int);
extern int destroy_items(struct monst *, int, int) NONNULLARG1;
extern int resist(struct monst *, char, int, int) NONNULLARG1;
extern void wish_history_add(char *);
extern void wish_history_flush(void);
extern void makewish(void);
extern const char *flash_str(int, boolean) NONNULL;

View File

@@ -1111,6 +1111,7 @@ freedynamicdata(void)
cmdq_clear(CQ_REPEAT);
cmdbind_freeall();
free_tutorial(); /* (only needed if quitting while in tutorial) */
wish_history_flush();
/* per-turn data, but might get added to when freeing other stuff */
dobjsfree(); /* really free deleted objects */

View File

@@ -6240,13 +6240,28 @@ wish_history_add(char *buf)
if (wish_history[idx])
free(wish_history[idx]);
wish_history[idx] = (char *)alloc(strlen(buf) + 1);
wish_history[idx] = (char *) alloc(strlen(buf) + 1);
strcpy(wish_history[idx], buf);
wish_history_idx = (wish_history_idx + 1) % MAX_WISH_HISTORY;
}
#endif /* DEBUG */
}
/* release any old wish text; called from freedynamicdata(save.c) */
void
wish_history_flush(void)
{
#ifdef DEBUG
int idx;
for (idx = 0; idx < MAX_WISH_HISTORY; ++idx) {
if (wish_history[idx])
free((genericptr_t) wish_history[idx]), wish_history[idx] = NULL;
}
wish_history_idx = 0;
#endif
}
/* shows menu of previous wishes, copies selected into buf, max BUFSZ len.
buf is not modified, if nothing was selected. */
staticfn void