improved regexp handling

If regex_compile() fails, free the regexp before doing anything else
in case failure reason is "out of memory".  Feedback to the user is
highly likely to panic or crash after memory runs out; this should
let the regex failure message be issued and the game continue.

User sound regular expressions were never freed.  This frees them
when FREE_ALL_MEMORY is enabled.
This commit is contained in:
PatR
2020-05-23 12:51:01 -07:00
parent 1d7ee022e6
commit 298331fe04
5 changed files with 91 additions and 41 deletions

View File

@@ -1,4 +1,4 @@
/* NetHack 3.7 files.c $NHDT-Date: 1589580856 2020/05/15 22:14:16 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.313 $ */
/* NetHack 3.7 files.c $NHDT-Date: 1590263451 2020/05/23 19:50:51 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.314 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Derek S. Ray, 2015. */
/* NetHack may be freely redistributed. See license for details. */
@@ -120,7 +120,7 @@ extern char *FDECL(translate_path_variables, (const char *, char *));
#endif
#ifdef USER_SOUNDS
extern char *sounddir;
extern char *sounddir; /* defined in sounds.c */
#endif
#if defined(UNIX) && defined(QT_GRAPHICS)
@@ -2885,6 +2885,8 @@ char *origbuf;
#endif /*AMIGA*/
#ifdef USER_SOUNDS
} else if (match_varname(buf, "SOUNDDIR", 8)) {
if (sounddir)
free((genericptr_t) sounddir);
sounddir = dupstr(bufp);
} else if (match_varname(buf, "SOUND", 5)) {
add_sound_mapping(bufp);