release wish history memory
The memory leak only happened at end of game so wasn't a big deal.
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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 */
|
||||
|
||||
17
src/zap.c
17
src/zap.c
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user