On 11 July 2014 12:41, Doug Hogan <d...@acyclic.org> wrote:
>
> Index: bin/csh/dol.c
> ===================================================================
> RCS file: /cvs/src/bin/csh/dol.c,v
> retrieving revision 1.17
> diff -u -p -d -r1.17 dol.c
> --- bin/csh/dol.c       12 Aug 2010 02:00:27 -0000      1.17
> +++ bin/csh/dol.c       11 Jul 2014 09:12:11 -0000
> @@ -829,7 +829,8 @@ heredoc(Char *term)
>
>      if (mkstemp(tmp) < 0)
>         stderror(ERR_SYSTEM, tmp, strerror(errno));
> -    (void) unlink(tmp);                /* 0 0 inode! */
> +    else
> +       (void) unlink(tmp);             /* 0 0 inode! */
>      Dv[0] = term;
>      Dv[1] = NULL;
>      gflag = 0;
> Index: sbin/disklabel/disklabel.c
> ===================================================================
> RCS file: /cvs/src/sbin/disklabel/disklabel.c,v
> retrieving revision 1.195
> diff -u -p -d -r1.195 disklabel.c
> --- sbin/disklabel/disklabel.c  5 May 2014 16:33:34 -0000       1.195
> +++ sbin/disklabel/disklabel.c  11 Jul 2014 09:13:43 -0000
> @@ -815,9 +815,12 @@ edit(struct disklabel *lp, int f)
>         FILE *fp;
>         u_int64_t total_sectors, starting_sector, ending_sector;
>
> -       if ((fd = mkstemp(tmpfil)) == -1 || (fp = fdopen(fd, "w")) == NULL) {
> -               if (fd != -1)
> +       if ((fd = mkstemp(tmpfil)) == -1 ||
> +           (fp = fdopen(fd, "w")) == NULL) {
> +               if (fd != -1) {
> +                       unlink(tmpfil);
>                         close(fd);
> +               }
>                 warn("%s", tmpfil);
>                 return (1);
>         }
> Index: sbin/scsi/scsi.c
> ===================================================================
> RCS file: /cvs/src/sbin/scsi/scsi.c,v
> retrieving revision 1.28
> diff -u -p -d -r1.28 scsi.c
> --- sbin/scsi/scsi.c    12 Nov 2013 04:59:02 -0000      1.28
> +++ sbin/scsi/scsi.c    11 Jul 2014 09:13:44 -0000
> @@ -571,8 +571,11 @@ edit_init(void)
>         strlcpy(edit_name, "/var/tmp/scXXXXXXXX", sizeof edit_name);
>         if ((fd = mkstemp(edit_name)) == -1)
>                 err(1, "mkstemp");
> -       if ( (edit_file = fdopen(fd, "w+")) == 0)
> +       if ( (edit_file = fdopen(fd, "w+")) == 0) {
> +               unlink(edit_name);
> +               close(fd);
>                 err(1, "fdopen");
> +       }
>         edit_opened = 1;
>
>         atexit(edit_done);
> Index: usr.bin/gzsig/sign.c
> ===================================================================
> RCS file: /cvs/src/usr.bin/gzsig/sign.c,v
> retrieving revision 1.13
> diff -u -p -d -r1.13 sign.c
> --- usr.bin/gzsig/sign.c        10 Mar 2013 10:36:57 -0000      1.13
> +++ usr.bin/gzsig/sign.c        11 Jul 2014 09:14:10 -0000
> @@ -281,6 +281,7 @@ sign(int argc, char *argv[])
>                 if ((fout = fdopen(fd, "w")) == NULL) {
>                         fprintf(stderr, "Error opening %s: %s\n",
>                             tmppath, strerror(errno));
> +                       unlink(tmppath);
>                         fclose(fin);
>                         close(fd);
>                         continue;
> @@ -288,6 +289,7 @@ sign(int argc, char *argv[])
>                 if (copy_permissions(fileno(fin), fd) < 0) {
>                         fprintf(stderr, "Error initializing %s: %s\n",
>                             tmppath, strerror(errno));
> +                       unlink(tmppath);
>                         fclose(fin);
>                         fclose(fout);
>                         continue;
> Index: usr.bin/htpasswd/htpasswd.c
> ===================================================================
> RCS file: /cvs/src/usr.bin/htpasswd/htpasswd.c,v
> retrieving revision 1.10
> diff -u -p -d -r1.10 htpasswd.c
> --- usr.bin/htpasswd/htpasswd.c 24 Mar 2014 20:33:01 -0000      1.10
> +++ usr.bin/htpasswd/htpasswd.c 11 Jul 2014 09:14:10 -0000
> @@ -164,8 +164,10 @@ main(int argc, char** argv)
>                         if ((fd = mkstemp(tmpl)) == -1)
>                                 err(1, "mkstemp");
>
> -                       if ((out = fdopen(fd, "w+")) == NULL)
> +                       if ((out = fdopen(fd, "w+")) == NULL) {
> +                               unlink(tmpl);
>                                 err(1, "cannot open tempfile");
> +                       }
>
>                         while ((linelen = getline(&line, &linesize, in))
>                             != -1) {
> Index: usr.bin/m4/eval.c
> ===================================================================
> RCS file: /cvs/src/usr.bin/m4/eval.c,v
> retrieving revision 1.72
> diff -u -p -d -r1.72 eval.c
> --- usr.bin/m4/eval.c   28 Apr 2014 12:34:11 -0000      1.72
> +++ usr.bin/m4/eval.c   11 Jul 2014 09:14:11 -0000
> @@ -818,8 +818,11 @@ dodiv(int n)
>                 char fname[] = _PATH_DIVNAME;
>
>                 if ((fd = mkstemp(fname)) < 0 ||
> -                       (outfile[n] = fdopen(fd, "w+")) == NULL)
> +                       (outfile[n] = fdopen(fd, "w+")) == NULL) {
> +                               if (fd != -1)
> +                                       unlink(fname);
>                                 err(1, "%s: cannot divert", fname);
> +               }
>                 if (unlink(fname) == -1)
>                         err(1, "%s: cannot unlink", fname);
>         }
> Index: usr.bin/rwall/rwall.c
> ===================================================================
> RCS file: /cvs/src/usr.bin/rwall/rwall.c,v
> retrieving revision 1.12
> diff -u -p -d -r1.12 rwall.c
> --- usr.bin/rwall/rwall.c       27 Oct 2009 23:59:43 -0000      1.12
> +++ usr.bin/rwall/rwall.c       11 Jul 2014 09:14:13 -0000
> @@ -112,8 +112,14 @@ makemsg(char *fname)
>         char *whom, hostname[MAXHOSTNAMELEN], lbuf[100], tmpname[MAXPATHLEN];
>
>         snprintf(tmpname, sizeof(tmpname), "%s/wall.XXXXXXXXXX", _PATH_TMP);
> -       if ((fd = mkstemp(tmpname)) == -1 || !(fp = fdopen(fd, "r+")))
> +       if ((fd = mkstemp(tmpname)) == -1 ||
> +           (fp = fdopen(fd, "r+")) == NULL) {
> +               if (fd != -1) {
> +                       unlink(tmpname);
> +                       close(fd);
> +               }
>                 err(1, "can't open temporary file");
> +       }
>         (void)unlink(tmpname);
>
>         if (!(whom = getlogin()))
> Index: usr.bin/sort/sort.c
> ===================================================================
> RCS file: /cvs/src/usr.bin/sort/sort.c,v
> retrieving revision 1.41
> diff -u -p -d -r1.41 sort.c
> --- usr.bin/sort/sort.c 13 Nov 2013 15:07:27 -0000      1.41
> +++ usr.bin/sort/sort.c 11 Jul 2014 09:14:13 -0000
> @@ -282,8 +282,13 @@ main(int argc, char *argv[])
>                 (void)umask(um);
>                 if ((outfd = mkstemp(toutpath)) == -1 ||
>                     fchmod(outfd, DEFFILEMODE & ~um) == -1 ||
> -                   (outfp = fdopen(outfd, "w")) == NULL)
> +                   (outfp = fdopen(outfd, "w")) == NULL) {
> +                       if (outfd != -1) {
> +                               unlink(toutpath);
> +                               close(outfd);
> +                       }
>                         err(2, "%s", toutpath);
> +               }
>                 outfile = toutpath;
>
>                 (void)atexit(cleanup);
> Index: usr.bin/sort/tmp.c
> ===================================================================
> RCS file: /cvs/src/usr.bin/sort/tmp.c,v
> retrieving revision 1.9
> diff -u -p -d -r1.9 tmp.c
> --- usr.bin/sort/tmp.c  27 Oct 2009 23:59:43 -0000      1.9
> +++ usr.bin/sort/tmp.c  11 Jul 2014 09:14:13 -0000
> @@ -65,8 +65,10 @@ ftmp(void)
>         (void)sigprocmask(SIG_BLOCK, &set, &oset);
>         if ((fd = mkstemp(path)) < 0)
>                 err(2, "%s", path);
> -       if (!(fp = fdopen(fd, "w+")))
> +       if (!(fp = fdopen(fd, "w+"))) {
> +               (void)unlink(path);
>                 err(2, "%s", path);
> +       }
>         (void)unlink(path);
>
>         (void)sigprocmask(SIG_SETMASK, &oset, NULL);
> Index: usr.bin/ssh/moduli.c
> ===================================================================
> RCS file: /cvs/src/usr.bin/ssh/moduli.c,v
> retrieving revision 1.28
> diff -u -p -d -r1.28 moduli.c
> --- usr.bin/ssh/moduli.c        24 Oct 2013 00:49:49 -0000      1.28
> +++ usr.bin/ssh/moduli.c        11 Jul 2014 09:14:14 -0000
> @@ -457,6 +457,7 @@ write_checkpoint(char *cpfile, u_int32_t
>         }
>         if ((fp = fdopen(r, "w")) == NULL) {
>                 logit("write_checkpoint: fdopen: %s", strerror(errno));
> +               unlink(tmp);
>                 close(r);
>                 return;
>         }
> Index: usr.bin/tic/tic.c
> ===================================================================
> RCS file: /cvs/src/usr.bin/tic/tic.c,v
> retrieving revision 1.31
> diff -u -p -d -r1.31 tic.c
> --- usr.bin/tic/tic.c   28 Nov 2013 18:24:55 -0000      1.31
> +++ usr.bin/tic/tic.c   11 Jul 2014 09:14:15 -0000
> @@ -460,11 +460,18 @@ matches(char **needle, const char *hayst
>  static FILE *
>  open_tempfile(char *name)
>  {
> -    FILE *result = 0;
> +    FILE *result;
>  #if HAVE_MKSTEMP
> -    int fd = mkstemp(name);
> -    if (fd >= 0)
> -       result = fdopen(fd, "w");
> +    int fd;
> +
> +    if ((fd = mkstemp(name)) == -1 ||
> +        (result = fdopen(fd, "w")) == NULL) {
> +            if (fd != -1) {
> +                unlink(name);
> +                close(fd);
> +            }
> +            return (NULL);
> +    }
>  #else
>      if (tmpnam(name) != 0)
>         result = fopen(name, "w");
> Index: usr.sbin/user/user.c
> ===================================================================
> RCS file: /cvs/src/usr.sbin/user/user.c,v
> retrieving revision 1.98
> diff -u -p -d -r1.98 user.c
> --- usr.sbin/user/user.c        23 Nov 2013 17:14:05 -0000      1.98
> +++ usr.sbin/user/user.c        11 Jul 2014 09:14:31 -0000
> @@ -721,6 +721,8 @@ setdefaults(user_t *up)
>         }
>         if ((fp = fdopen(fd, "w")) == NULL) {
>                 warn("can't fdopen `%s' for writing", CONFFILE);
> +               unlink(template);
> +               close(fd);
>                 return 0;
>         }
>         ret = 1;

Hello Doug,

not sure whether it's my eyes or the Gmail client but looks like you
are using spaces for indention. Preferred way is to use tabs.

--
Kind regards,
Ville Valkonen

Reply via email to