Avoid possible double fclose()
authorSepherosa Ziehau <sephe@dragonflybsd.org>
Sat, 24 Jun 2006 00:04:18 +0000 (00:04 +0000)
committerSepherosa Ziehau <sephe@dragonflybsd.org>
Sat, 24 Jun 2006 00:04:18 +0000 (00:04 +0000)
Obtained via OpenBSD from coverity/NetBSD

usr.bin/vi/Makefile
usr.bin/vi/patches/ex_write.c.patch [new file with mode: 0644]

index 87bb958..1eb7fe2 100644 (file)
@@ -1,14 +1,13 @@
 #
 # $FreeBSD: src/usr.bin/vi/Makefile,v 1.27.2.7 2002/08/07 16:32:01 ru Exp $
-# $DragonFly: src/usr.bin/vi/Makefile,v 1.4 2006/02/26 17:18:04 dillon Exp $
+# $DragonFly: src/usr.bin/vi/Makefile,v 1.5 2006/06/24 00:04:18 sephe Exp $
 #
 # This has most of the glue needed to compile tknvi and the perl hooks,
 # but not all.
 #
 
 SRCDIR=                ${.CURDIR}/../../contrib/nvi
-PATCHES!=       echo ${.CURDIR}/patches/*.patch
-CONTRIBDIR=    ${SRCDIR}/vi
+CONTRIBDIR=    ${SRCDIR}
 
 .if defined(RELEASE_CRUNCH)
 # When building `vi' for the fixit floppy, don't include any of the
@@ -143,7 +142,6 @@ SRCS+=      getc.c v_at.c v_ch.c v_cmd.c v_delete.c v_ex.c v_increment.c v_init.c \
        v_replace.c v_right.c v_screen.c v_scroll.c v_search.c v_section.c \
        v_sentence.c v_status.c v_txt.c v_ulcase.c v_undo.c \
        v_util.c v_word.c v_xchar.c v_yank.c v_z.c v_zexit.c vi.c
-SRCS+= ${PATCHES}
 
 # Vi screen source.
 SRCS+= vs_line.c vs_msg.c vs_refresh.c vs_relative.c vs_smap.c vs_split.c
@@ -167,6 +165,12 @@ ex_notcl.c: ex_tcl.c
 ex_noperl.c: ex_perl.c
        -unifdef -UHAVE_PERL_INTERP ${SRCDIR}/ex/ex_perl.c > ${.TARGET}
 
+v_ex.c: ${CONTRIBDIR}/vi/v_ex.c ${.CURDIR}/patches/v_ex.c.patch
+       patch -o ${.TARGET} -i ${.ALLSRC:M*.patch} ${CONTRIBDIR}/vi/${.TARGET}
+
+ex_write.c: ${CONTRIBDIR}/ex/ex_write.c ${.CURDIR}/patches/ex_write.c.patch
+       patch -o ${.TARGET} -i ${.ALLSRC:M*.patch} ${CONTRIBDIR}/ex/${.TARGET}
+
 CLEANFILES+=   ex_notcl.c ex_noperl.c
 
 afterinstall:
diff --git a/usr.bin/vi/patches/ex_write.c.patch b/usr.bin/vi/patches/ex_write.c.patch
new file mode 100644 (file)
index 0000000..8299949
--- /dev/null
@@ -0,0 +1,23 @@
+/* $DragonFly: src/usr.bin/vi/patches/ex_write.c.patch,v 1.1 2006/06/24 00:04:18 sephe Exp $ */
+--- ex_write.c 2006-06-23 23:08:03.000000000 +0800
++++ ex_write.c 2006-06-23 23:08:54.000000000 +0800
+@@ -352,14 +352,17 @@
+           S_ISREG(sb.st_mode) && fsync(fileno(fp)))
+               goto err;
+-      if (fclose(fp))
++      if (fclose(fp)) {
++              fp = NULL;
+               goto err;
++      }
+       rval = 0;
+       if (0) {
+ err:          if (!F_ISSET(sp->ep, F_MULTILOCK))
+                       msgq_str(sp, M_SYSERR, name, "%s");
+-              (void)fclose(fp);
++              if (fp != NULL)
++                      fclose(fp);
+               rval = 1;
+       }