minor memory leak

I ran the fuzzer with MONITOR_HEAP enabled and heaputil found a dozen
or so un-free'd allocations, all made by the same dupstr() call in
special_handling() for "symset" and "roguesymset".  (Reproducible with
a few tens of thousands of fuzzer moves, although you have to take
over from the fuzzer and make a clean exit rather than just interrupt
it or there'll be lots of other un-free'd memory.)  I haven't actually
figured out how/why it was leaking, but reorganizing the code has made
the leak go away (according to a couple of even longer fuzzer runs) so
I'm settling for that.
This commit is contained in:
PatR
2018-12-29 20:41:16 -08:00
parent 39b6f7f462
commit adf64764f4
2 changed files with 46 additions and 89 deletions

View File

@@ -1,4 +1,4 @@
/* NetHack 3.6 files.c $NHDT-Date: 1545702598 2018/12/25 01:49:58 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.248 $ */
/* NetHack 3.6 files.c $NHDT-Date: 1546144856 2018/12/30 04:40:56 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.249 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Derek S. Ray, 2015. */
/* NetHack may be freely redistributed. See license for details. */
@@ -3264,37 +3264,26 @@ int which_set;
switch (symp->idx) {
case 0:
tmpsp =
(struct symsetentry *) alloc(sizeof (struct symsetentry));
tmpsp->next = (struct symsetentry *) 0;
if (!symset_list) {
symset_list = tmpsp;
symset_count = 0;
} else {
symset_count++;
tmpsp->next = symset_list;
symset_list = tmpsp;
}
tmpsp->idx = symset_count;
tmpsp = (struct symsetentry *) alloc(sizeof *tmpsp);
tmpsp->next = symset_list;
symset_list = tmpsp;
tmpsp->idx = symset_count++;
tmpsp->name = dupstr(bufp);
tmpsp->desc = (char *) 0;
tmpsp->nocolor = 0;
tmpsp->handling = H_UNK;
/* initialize restriction bits */
tmpsp->nocolor = 0;
tmpsp->primary = 0;
tmpsp->rogue = 0;
break;
case 2:
/* handler type identified */
tmpsp = symset_list; /* most recent symset */
tmpsp->handling = H_UNK;
i = 0;
while (known_handling[i]) {
for (i = 0; known_handling[i]; ++i)
if (!strcmpi(known_handling[i], bufp)) {
tmpsp->handling = i;
break; /* while loop */
break; /* for loop */
}
i++;
}
break;
case 3: /* description:something */
tmpsp = symset_list; /* most recent symset */