Author: truckman
Date: Mon May 23 04:47:24 2016
New Revision: 300449
URL: https://svnweb.freebsd.org/changeset/base/300449

Log:
  MFC r299893
  
  Don't free fnamebuf before we calling cfgfile_add().  This changes a
  use-after-free error into a minor memory leak.
  
  Reported by:  Coverity
  CID:          1006084

Modified:
  stable/10/usr.sbin/config/lang.l
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/usr.sbin/config/lang.l
==============================================================================
--- stable/10/usr.sbin/config/lang.l    Mon May 23 04:17:27 2016        
(r300448)
+++ stable/10/usr.sbin/config/lang.l    Mon May 23 04:47:24 2016        
(r300449)
@@ -267,7 +267,8 @@ include(const char *fname, int ateof)
                asprintf(&fnamebuf, "../../conf/%s", fname);
                if (fnamebuf != NULL) {
                        fp = fopen(fnamebuf, "r");
-                       free(fnamebuf);
+                       if (fp == NULL)
+                               free(fnamebuf);
                }
        }
        if (fp == NULL) {
@@ -275,10 +276,10 @@ include(const char *fname, int ateof)
                        asprintf(&fnamebuf, "%s/%s", ipath->path, fname);
                        if (fnamebuf != NULL) {
                                fp = fopen(fnamebuf, "r");
-                               free(fnamebuf);
                        }
                        if (fp != NULL)
                                break;
+                       free(fnamebuf);
                }
        }
        if (fp == NULL) {
_______________________________________________
[email protected] mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "[email protected]"

Reply via email to