plug open file leaks for rumors and oracles
If the rumors file or oralces file got opened successfully but had bad data, it wouldn't be closed.
This commit is contained in:
17
src/rumors.c
17
src/rumors.c
@@ -1,4 +1,4 @@
|
|||||||
/* NetHack 3.6 rumors.c $NHDT-Date: 1542422933 2018/11/17 02:48:53 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.30 $ */
|
/* NetHack 3.6 rumors.c $NHDT-Date: 1545132266 2018/12/18 11:24:26 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.34 $ */
|
||||||
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
|
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
|
||||||
/*-Copyright (c) Robert Patrick Rankin, 2012. */
|
/*-Copyright (c) Robert Patrick Rankin, 2012. */
|
||||||
/* NetHack may be freely redistributed. See license for details. */
|
/* NetHack may be freely redistributed. See license for details. */
|
||||||
@@ -183,13 +183,15 @@ boolean exclude_cookie;
|
|||||||
void
|
void
|
||||||
rumor_check()
|
rumor_check()
|
||||||
{
|
{
|
||||||
dlb *rumors;
|
dlb *rumors = 0;
|
||||||
winid tmpwin;
|
winid tmpwin;
|
||||||
char *endp, line[BUFSZ], xbuf[BUFSZ], rumor_buf[BUFSZ];
|
char *endp, line[BUFSZ], xbuf[BUFSZ], rumor_buf[BUFSZ];
|
||||||
|
|
||||||
if (true_rumor_size < 0L) { /* we couldn't open RUMORFILE */
|
if (true_rumor_size < 0L) { /* we couldn't open RUMORFILE */
|
||||||
no_rumors:
|
no_rumors:
|
||||||
pline("rumors not accessible.");
|
pline("rumors not accessible.");
|
||||||
|
if (rumors)
|
||||||
|
(void) dlb_fclose(rumors);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -423,11 +425,10 @@ outoracle(special, delphi)
|
|||||||
boolean special;
|
boolean special;
|
||||||
boolean delphi;
|
boolean delphi;
|
||||||
{
|
{
|
||||||
char line[COLNO];
|
winid tmpwin;
|
||||||
char *endp;
|
|
||||||
dlb *oracles;
|
dlb *oracles;
|
||||||
int oracle_idx;
|
int oracle_idx;
|
||||||
char xbuf[BUFSZ];
|
char *endp, line[COLNO], xbuf[BUFSZ];
|
||||||
|
|
||||||
/* early return if we couldn't open ORACLEFILE on previous attempt,
|
/* early return if we couldn't open ORACLEFILE on previous attempt,
|
||||||
or if all the oracularities are already exhausted */
|
or if all the oracularities are already exhausted */
|
||||||
@@ -437,17 +438,16 @@ boolean delphi;
|
|||||||
oracles = dlb_fopen(ORACLEFILE, "r");
|
oracles = dlb_fopen(ORACLEFILE, "r");
|
||||||
|
|
||||||
if (oracles) {
|
if (oracles) {
|
||||||
winid tmpwin;
|
|
||||||
if (oracle_flg == 0) { /* if this is the first outoracle() */
|
if (oracle_flg == 0) { /* if this is the first outoracle() */
|
||||||
init_oracles(oracles);
|
init_oracles(oracles);
|
||||||
oracle_flg = 1;
|
oracle_flg = 1;
|
||||||
if (oracle_cnt == 0)
|
if (oracle_cnt == 0)
|
||||||
return;
|
goto close_oracles;
|
||||||
}
|
}
|
||||||
/* oracle_loc[0] is the special oracle;
|
/* oracle_loc[0] is the special oracle;
|
||||||
oracle_loc[1..oracle_cnt-1] are normal ones */
|
oracle_loc[1..oracle_cnt-1] are normal ones */
|
||||||
if (oracle_cnt <= 1 && !special)
|
if (oracle_cnt <= 1 && !special)
|
||||||
return; /*(shouldn't happen)*/
|
goto close_oracles; /*(shouldn't happen)*/
|
||||||
oracle_idx = special ? 0 : rnd((int) oracle_cnt - 1);
|
oracle_idx = special ? 0 : rnd((int) oracle_cnt - 1);
|
||||||
(void) dlb_fseek(oracles, (long) oracle_loc[oracle_idx], SEEK_SET);
|
(void) dlb_fseek(oracles, (long) oracle_loc[oracle_idx], SEEK_SET);
|
||||||
if (!special) /* move offset of very last one into this slot */
|
if (!special) /* move offset of very last one into this slot */
|
||||||
@@ -470,6 +470,7 @@ boolean delphi;
|
|||||||
}
|
}
|
||||||
display_nhwindow(tmpwin, TRUE);
|
display_nhwindow(tmpwin, TRUE);
|
||||||
destroy_nhwindow(tmpwin);
|
destroy_nhwindow(tmpwin);
|
||||||
|
close_oracles:
|
||||||
(void) dlb_fclose(oracles);
|
(void) dlb_fclose(oracles);
|
||||||
} else {
|
} else {
|
||||||
couldnt_open_file(ORACLEFILE);
|
couldnt_open_file(ORACLEFILE);
|
||||||
|
|||||||
Reference in New Issue
Block a user