]> granicus.if.org Git - nethack/commitdiff
plug open file leaks for rumors and oracles
authorPatR <rankin@nethack.org>
Tue, 18 Dec 2018 11:24:38 +0000 (03:24 -0800)
committerPatR <rankin@nethack.org>
Tue, 18 Dec 2018 11:24:38 +0000 (03:24 -0800)
If the rumors file or oralces file got opened successfully but had bad
data, it wouldn't be closed.

src/rumors.c

index a0f367952c662ffda27b6c7952fb2e89066db65d..033a0126cecad390b81e8630eea49016675360ab 100644 (file)
@@ -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) Robert Patrick Rankin, 2012. */
 /* NetHack may be freely redistributed.  See license for details. */
@@ -183,13 +183,15 @@ boolean exclude_cookie;
 void
 rumor_check()
 {
-    dlb *rumors;
+    dlb *rumors = 0;
     winid tmpwin;
     char *endp, line[BUFSZ], xbuf[BUFSZ], rumor_buf[BUFSZ];
 
     if (true_rumor_size < 0L) { /* we couldn't open RUMORFILE */
     no_rumors:
         pline("rumors not accessible.");
+        if (rumors)
+            (void) dlb_fclose(rumors);
         return;
     }
 
@@ -423,11 +425,10 @@ outoracle(special, delphi)
 boolean special;
 boolean delphi;
 {
-    char line[COLNO];
-    char *endp;
+    winid tmpwin;
     dlb *oracles;
     int oracle_idx;
-    char xbuf[BUFSZ];
+    char *endp, line[COLNO], xbuf[BUFSZ];
 
     /* early return if we couldn't open ORACLEFILE on previous attempt,
        or if all the oracularities are already exhausted */
@@ -437,17 +438,16 @@ boolean delphi;
     oracles = dlb_fopen(ORACLEFILE, "r");
 
     if (oracles) {
-        winid tmpwin;
         if (oracle_flg == 0) { /* if this is the first outoracle() */
             init_oracles(oracles);
             oracle_flg = 1;
             if (oracle_cnt == 0)
-                return;
+                goto close_oracles;
         }
         /* oracle_loc[0] is the special oracle;
            oracle_loc[1..oracle_cnt-1] are normal ones */
         if (oracle_cnt <= 1 && !special)
-            return; /*(shouldn't happen)*/
+            goto close_oracles; /*(shouldn't happen)*/
         oracle_idx = special ? 0 : rnd((int) oracle_cnt - 1);
         (void) dlb_fseek(oracles, (long) oracle_loc[oracle_idx], SEEK_SET);
         if (!special) /* move offset of very last one into this slot */
@@ -470,6 +470,7 @@ boolean delphi;
         }
         display_nhwindow(tmpwin, TRUE);
         destroy_nhwindow(tmpwin);
+ close_oracles:
         (void) dlb_fclose(oracles);
     } else {
         couldnt_open_file(ORACLEFILE);