Author: avos
Date: Sat Feb 16 00:37:08 2019
New Revision: 344193
URL: https://svnweb.freebsd.org/changeset/base/344193

Log:
  MFC r343909:
  newkey(8): fix 'tmpname' memory leak (always) and input file descriptor leak
  when output file cannot be opened
  
  PR:           201732
  Reported by:  David Binderman <dcb...@hotmail.com>

Modified:
  stable/10/usr.bin/newkey/update.c
Directory Properties:
  stable/10/   (props changed)

Changes in other areas also in this revision:
Modified:
  stable/11/usr.bin/newkey/update.c
  stable/12/usr.bin/newkey/update.c
Directory Properties:
  stable/11/   (props changed)
  stable/12/   (props changed)

Modified: stable/10/usr.bin/newkey/update.c
==============================================================================
--- stable/10/usr.bin/newkey/update.c   Sat Feb 16 00:15:54 2019        
(r344192)
+++ stable/10/usr.bin/newkey/update.c   Sat Feb 16 00:37:08 2019        
(r344193)
@@ -266,11 +266,14 @@ localupdate(char *name, char *filename, u_int op, u_in
        sprintf(tmpname, "%s.tmp", filename);
        rf = fopen(filename, "r");
        if (rf == NULL) {
-               return (ERR_READ);
+               err = ERR_READ;
+               goto cleanup;
        }
        wf = fopen(tmpname, "w");
        if (wf == NULL) {
-               return (ERR_WRITE);
+               fclose(rf);
+               err = ERR_WRITE;
+               goto cleanup;
        }
        err = -1;
        while (fgets(line, sizeof (line), rf)) {
@@ -310,13 +313,18 @@ localupdate(char *name, char *filename, u_int op, u_in
        fclose(rf);
        if (err == 0) {
                if (rename(tmpname, filename) < 0) {
-                       return (ERR_DBASE);
+                       err = ERR_DBASE;
+                       goto cleanup;
                }
        } else {
                if (unlink(tmpname) < 0) {
-                       return (ERR_DBASE);
+                       err = ERR_DBASE;
+                       goto cleanup;
                }
        }
+
+cleanup:
+       free(tmpname);
        return (err);
 }
 
_______________________________________________
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"

Reply via email to