Bug 201732 - usr/src/usr.bin/newkey/update.c: two memory leaks and a resource leak
Summary: usr/src/usr.bin/newkey/update.c: two memory leaks and a resource leak
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: misc (show other bugs)
Version: 10.2-STABLE
Hardware: Any Any
: --- Affects Some People
Assignee: Andriy Voskoboinyk
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-07-21 07:34 UTC by David Binderman
Modified: 2019-02-16 00:38 UTC (History)
1 user (show)

See Also:
avos: mfc-stable10+
avos: mfc-stable11+
avos: mfc-stable12+


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Binderman 2015-07-21 07:34:48 UTC
1.

[usr/src/usr.bin/newkey/update.c:269]: (error) Memory leak: tmpname

    tmpname = malloc(strlen(filename) + 4);
    if (tmpname == NULL) {
        return (ERR_MALLOC);
    }
    sprintf(tmpname, "%s.tmp", filename);
    rf = fopen(filename, "r");
    if (rf == NULL) {
        return (ERR_READ);
    }

2.

[usr/src/usr.bin/newkey/update.c:320]: (error) Memory leak: tmpname

    }
    return (err);
}
Comment 1 David Binderman 2015-12-02 08:38:31 UTC
[usr/src/usr.bin/newkey/update.c:273]: (error) Resource leak: rf

    if (wf == NULL) {
        return (ERR_WRITE);
    }
Comment 2 commit-hook freebsd_committer 2019-02-08 14:32:01 UTC
A commit references this bug:

Author: avos
Date: Fri Feb  8 14:31:44 UTC 2019
New revision: 343909
URL: https://svnweb.freebsd.org/changeset/base/343909

Log:
  newkey(8): fix 'tmpname' memory leak (always) and input file descriptor leak
  when output file cannot be opened

  PR:		201732
  Reported by:	David Binderman <dcb314@hotmail.com>
  MFC after:	1 week

Changes:
  head/usr.bin/newkey/update.c
Comment 3 commit-hook freebsd_committer 2019-02-16 00:38:13 UTC
A commit references this bug:

Author: avos
Date: Sat Feb 16 00:37:09 UTC 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 <dcb314@hotmail.com>

Changes:
_U  stable/10/
  stable/10/usr.bin/newkey/update.c
_U  stable/11/
  stable/11/usr.bin/newkey/update.c
_U  stable/12/
  stable/12/usr.bin/newkey/update.c