From d80fd8a014c042157288912c635fd602c8adb85a Mon Sep 17 00:00:00 2001 From: PatR Date: Sat, 9 Feb 2019 15:30:53 -0800 Subject: [PATCH 1/4] curses status cleanup Stop the last of the memory leaks occuring during basic usage. --- include/wincurs.h | 2 +- win/curses/cursmain.c | 2 +- win/curses/cursstat.c | 7 ++++--- win/curses/curswins.c | 4 +--- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/include/wincurs.h b/include/wincurs.h index 43fdb9de6..cb43f3729 100644 --- a/include/wincurs.h +++ b/include/wincurs.h @@ -181,7 +181,7 @@ extern void curses_del_menu(winid wid); /* cursstat.c */ extern void curses_status_init(void); -extern void curses_teardown_status(void); +extern void curses_status_finish(void); extern void curses_status_update(int, genericptr_t, int, int, int, unsigned long *); diff --git a/win/curses/cursmain.c b/win/curses/cursmain.c index 8ae781a98..e792c9376 100644 --- a/win/curses/cursmain.c +++ b/win/curses/cursmain.c @@ -75,7 +75,7 @@ struct window_procs curses_procs = { genl_getmsghistory, genl_putmsghistory, curses_status_init, - genl_status_finish, + curses_status_finish, genl_status_enablefield, curses_status_update, genl_can_suspend_yes, diff --git a/win/curses/cursstat.c b/win/curses/cursstat.c index f1ad01741..67287ea88 100644 --- a/win/curses/cursstat.c +++ b/win/curses/cursstat.c @@ -58,15 +58,16 @@ curses_status_init() } void -curses_teardown_status() +curses_status_finish() { #ifdef STATUS_HILITES int i; for (i = 0; i < MAXBLSTATS; ++i) { - free(status_vals_long[i]); - status_vals_long[i] = (char *) 0; + if (status_vals_long[i]) + free(status_vals_long[i]), status_vals_long[i] = (char *) 0; } + genl_status_finish(); #endif /* STATUS_HILITES */ return; } diff --git a/win/curses/curswins.c b/win/curses/curswins.c index 45cd0f7ef..e78055475 100644 --- a/win/curses/curswins.c +++ b/win/curses/curswins.c @@ -313,9 +313,7 @@ curses_del_nhwin(winid wid) return; } if (wid == MESSAGE_WIN) { - curses_teardown_messages(); - } else if (wid == STATUS_WIN) { - curses_teardown_status(); + curses_teardown_messages(); } nhwins[wid].curwin = NULL; nhwins[wid].nhwin = -1; From 2d62513b1bb57e74ddd324be01fc0db47ceab984 Mon Sep 17 00:00:00 2001 From: PatR Date: Sat, 9 Feb 2019 15:33:16 -0800 Subject: [PATCH 2/4] minor nitpicks A couple of trivial things I noticed while looking at status cleanup. --- src/botl.c | 14 ++++++-------- win/tty/wintty.c | 4 ++-- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/botl.c b/src/botl.c index a527f6406..e58f5c398 100644 --- a/src/botl.c +++ b/src/botl.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 botl.c $NHDT-Date: 1545705812 2018/12/25 02:43:32 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.132 $ */ +/* NetHack 3.6 botl.c $NHDT-Date: 1549755174 2019/02/09 23:32:54 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.134 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /*-Copyright (c) Michael Allison, 2006. */ /* NetHack may be freely redistributed. See license for details. */ @@ -926,14 +926,12 @@ status_finish() free((genericptr_t) blstats[1][i].val), blstats[1][i].val = 0; #ifdef STATUS_HILITES if (blstats[0][i].thresholds) { - struct hilite_s *temp = blstats[0][i].thresholds, - *next = (struct hilite_s *)0; - while (temp) { + struct hilite_s *temp, *next = 0; + + for (temp = blstats[0][i].thresholds; temp; temp = next) { next = temp->next; - free(temp); - blstats[0][i].thresholds = (struct hilite_s *)0; - blstats[1][i].thresholds = blstats[0][i].thresholds; - temp = next; + free((genericptr_t) temp); + blstats[0][i].thresholds = blstats[1][i].thresholds = 0; } } #endif /* STATUS_HILITES */ diff --git a/win/tty/wintty.c b/win/tty/wintty.c index 1f863f159..c56e4576d 100644 --- a/win/tty/wintty.c +++ b/win/tty/wintty.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 wintty.c $NHDT-Date: 1549333450 2019/02/05 02:24:10 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.194 $ */ +/* NetHack 3.6 wintty.c $NHDT-Date: 1549755185 2019/02/09 23:33:05 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.195 $ */ /* Copyright (c) David Cohrs, 1991 */ /* NetHack may be freely redistributed. See license for details. */ @@ -1526,7 +1526,7 @@ boolean free_data; tty_menu_item *temp; while ((temp = cw->mlist) != 0) { - cw->mlist = cw->mlist->next; + cw->mlist = temp->next; if (temp->str) free((genericptr_t) temp->str); free((genericptr_t) temp); From 128d1628a93300e2abdb27075e9b67e23f3507eb Mon Sep 17 00:00:00 2001 From: PatR Date: Sat, 9 Feb 2019 16:07:18 -0800 Subject: [PATCH 3/4] fix #H8124 - interrupted donning gives player info about the armor. Wearing armor sets obj->known, making its enchantment be shown when it gets formatted, because the AC value on the status line lets the player deduce what that is. It was being set at the beginning of the wear operation. If the armor got stolen before it became fully worn, the enchantment was still shown. Defer that until the end of the operation. An attentive player can still deduce the enchantment if the item is stolen (because its protection starts immediately) but the hero won't learn that enchantment unless the donning completes. This might be suboptimal but it isn't qualitatively different from watching a pet walk/not-walk over items whose bless/curse state isn't known or dropping unidentified items in a shop to check their price. The player can deduce something that the hero doesn't know yet. --- doc/fixes36.2 | 5 ++++- src/do_wear.c | 34 ++++++++++++++++++---------------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/doc/fixes36.2 b/doc/fixes36.2 index da95df2c1..9f63b2e94 100644 --- a/doc/fixes36.2 +++ b/doc/fixes36.2 @@ -1,4 +1,4 @@ -$NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.252 $ $NHDT-Date: 1549666475 2019/02/08 22:54:35 $ +$NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.253 $ $NHDT-Date: 1549757225 2019/02/10 00:07:05 $ This fixes36.2 file is here to capture information about updates in the 3.6.x lineage following the release of 3.6.1 in April 2018. Please note, however, @@ -368,6 +368,9 @@ if game ends while hero is in a vault wall breach or in guard's temporary DUMPLOG: output from '/' (#whatis) and ';' went into ^P message recall history but was missing from DUMPLOG's message history due to special handling for the first character which might be graphical rather than text +when donning armor, defer flagging its +/- value--which can be deduced from + the status line--as known until finished in case it gets stolen before + then (player might still deduce the +/- value but hero won't learn it) Fixes to Post-3.6.1 Problems that Were Exposed Via git Repository diff --git a/src/do_wear.c b/src/do_wear.c index 843a1b084..e7e451a08 100644 --- a/src/do_wear.c +++ b/src/do_wear.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 do_wear.c $NHDT-Date: 1549406868 2019/02/05 22:47:48 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.104 $ */ +/* NetHack 3.6 do_wear.c $NHDT-Date: 1549757226 2019/02/10 00:07:06 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.105 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /*-Copyright (c) Robert Patrick Rankin, 2012. */ /* NetHack may be freely redistributed. See license for details. */ @@ -197,6 +197,7 @@ Boots_on(VOID_ARGS) default: impossible(unknown_type, c_boots, uarmf->otyp); } + uarmf->known = 1; /* boots' +/- evident because of status line AC */ return 0; } @@ -310,6 +311,7 @@ Cloak_on(VOID_ARGS) default: impossible(unknown_type, c_cloak, uarmc->otyp); } + uarmc->known = 1; /* cloak's +/- evident because of status line AC */ return 0; } @@ -425,6 +427,7 @@ Helmet_on(VOID_ARGS) default: impossible(unknown_type, c_helmet, uarmh->otyp); } + uarmh->known = 1; /* helmet's +/- evident because of status line AC */ return 0; } @@ -497,6 +500,7 @@ Gloves_on(VOID_ARGS) default: impossible(unknown_type, c_gloves, uarmg->otyp); } + uarmg->known = 1; /* gloves' +/- evident because of status line AC */ return 0; } @@ -587,7 +591,7 @@ Shield_on(VOID_ARGS) default: impossible(unknown_type, c_shield, uarms->otyp); } - + uarms->known = 1; /* shield's +/- evident because of status line AC */ return 0; } @@ -627,7 +631,7 @@ Shirt_on(VOID_ARGS) default: impossible(unknown_type, c_shirt, uarmu->otyp); } - + uarmu->known = 1; /* shirt's +/- evident because of status line AC */ return 0; } @@ -659,6 +663,7 @@ Armor_on(VOID_ARGS) * suits are set up as intrinsics (actually 'extrinsics') by setworn() * which is called by armor_or_accessory_on() before Armor_on(). */ + uarm->known = 1; /* suit's +/- evident because of status line AC */ return 0; } @@ -1908,23 +1913,20 @@ struct obj *obj; if (armor) { int delay; - /* - * FIXME: [#H8124] - * This (setting 'obj->known=1') takes places as soon as hero - * starts donning armor and sticks even if interrupted before - * finishing. (Most glaring instance is theft of this armor - * by a nymph but any interruption applies.) - * - * Perhaps setworn() (the reason to set obj->known=1) should - * be deferred until the (*aftermv)() action? But Boots_on()/ - * Helmet_on()/&c aren't passed this 'obj', they rely to uarmf/ - * uarmh/&c being assigned by setworn() before they're called. - */ - obj->known = 1; /* since AC is shown on the status line */ /* if the armor is wielded, release it for wearing (won't be welded even if cursed; that only happens for weapons/weptools) */ if (obj->owornmask & W_WEAPON) remove_worn_item(obj, FALSE); + /* + * Setting obj->known=1 is done because setworn() causes hero's AC + * to change so armor's +/- value is evident via the status line. + * We used to set it here because of that, but then it would stick + * if a nymph stole the armor before it was fully worn. Delay it + * until the aftermv action. The player may still know this armor's + * +/- amount if donning gets interruptted, but the hero won't. + * + obj->known = 1; + */ setworn(obj, mask); delay = -objects[obj->otyp].oc_delay; if (delay) { From 16dc5870cb5925e9697524e90bb928c4c7d6b173 Mon Sep 17 00:00:00 2001 From: PatR Date: Sat, 9 Feb 2019 16:27:51 -0800 Subject: [PATCH 4/4] comment typo --- src/do_wear.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/do_wear.c b/src/do_wear.c index e7e451a08..0c3a4c1f8 100644 --- a/src/do_wear.c +++ b/src/do_wear.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 do_wear.c $NHDT-Date: 1549757226 2019/02/10 00:07:06 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.105 $ */ +/* NetHack 3.6 do_wear.c $NHDT-Date: 1549758452 2019/02/10 00:27:32 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.106 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /*-Copyright (c) Robert Patrick Rankin, 2012. */ /* NetHack may be freely redistributed. See license for details. */ @@ -1923,7 +1923,7 @@ struct obj *obj; * We used to set it here because of that, but then it would stick * if a nymph stole the armor before it was fully worn. Delay it * until the aftermv action. The player may still know this armor's - * +/- amount if donning gets interruptted, but the hero won't. + * +/- amount if donning gets interrupted, but the hero won't. * obj->known = 1; */