Source-Changes-D archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: CVS commit: src/usr.sbin/envstat



Module Name:    src
Committed By:   christos
Date:           Thu Dec 13 19:31:25 UTC 2012

Modified Files:
        src/usr.sbin/envstat: envstat.c

Log Message:
PR/47316: Henning Petersen: Memory leak in envstat with config file.

While we're making sure to free() things, should we not also defend against memory leaks in the case where an option is used more than once?


RCS file: /cvsroot/src/usr.sbin/envstat/envstat.c,v
retrieving revision 1.92
diff -u -p -r1.92 envstat.c
--- envstat.c   13 Dec 2012 19:31:25 -0000      1.92
+++ envstat.c   13 Dec 2012 19:47:44 -0000
@@ -132,6 +132,7 @@ int main(int argc, char **argv)
        while ((c = getopt(argc, argv, "c:Dd:fIi:klrSs:Tw:Wx")) != -1) {
                switch (c) {
                case 'c':       /* configuration file */
+                       free(configfile);
                        configfile = strdup(optarg);
                        if (configfile == NULL)
                                err(EXIT_FAILURE, "strdup");
@@ -140,6 +141,7 @@ int main(int argc, char **argv)
                        flags |= ENVSYS_DFLAG;
                        break;
                case 'd':       /* show sensors of a specific device */
+                       free(mydevname);
                        mydevname = strdup(optarg);
                        if (mydevname == NULL)
                                err(EXIT_FAILURE, "strdup");
@@ -171,6 +173,7 @@ int main(int argc, char **argv)
                        flags |= ENVSYS_SFLAG;
                        break;
                case 's':       /* only show specified sensors */
+                       free(sensors);
                        sensors = strdup(optarg);
                        if (sensors == NULL)
                                err(EXIT_FAILURE, "strdup");



-------------------------------------------------------------------------
| Paul Goyette     | PGP Key fingerprint:     | E-mail addresses:       |
| Customer Service | FA29 0E3B 35AF E8AE 6651 | paul at whooppee.com    |
| Network Engineer | 0786 F758 55DE 53BA 7731 | pgoyette at juniper.net |
| Kernel Developer |                          | pgoyette at netbsd.org  |
-------------------------------------------------------------------------


Home | Main Index | Thread Index | Old Index