Author: stevek
Date: Wed Dec  6 21:18:45 2017
New Revision: 326636
URL: https://svnweb.freebsd.org/changeset/base/326636

Log:
  The function make_relative_prefix_1 does not properly free locally
  allocated memory when it returns early.
  
  Free the memory associated with the variables full_programe, bin_dirs,
  prog_dirs, and prefix_dirs when the function returns early.
  
  Submitted by: Tom Rix <t...@juniper.net>
  Reviewed by:  jhibbits, emaste
  Approved by:  sjg (mentor)
  Obtained from:        Juniper Networks, Inc.
  MFC after:    2 weeks
  Differential Revision:        https://reviews.freebsd.org/D9691

Modified:
  head/contrib/binutils/libiberty/make-relative-prefix.c

Modified: head/contrib/binutils/libiberty/make-relative-prefix.c
==============================================================================
--- head/contrib/binutils/libiberty/make-relative-prefix.c      Wed Dec  6 
21:12:24 2017        (r326635)
+++ head/contrib/binutils/libiberty/make-relative-prefix.c      Wed Dec  6 
21:18:45 2017        (r326636)
@@ -299,10 +299,18 @@ make_relative_prefix_1 (const char *progname, const ch
     full_progname = strdup(progname);
 
   prog_dirs = split_directories (full_progname, &prog_num);
-  bin_dirs = split_directories (bin_prefix, &bin_num);
+  if (prog_dirs == NULL)
+    {
+      free (full_progname);
+      return NULL;
+    }
   free (full_progname);
-  if (bin_dirs == NULL || prog_dirs == NULL)
-    return NULL;
+  bin_dirs = split_directories (bin_prefix, &bin_num);
+  if (bin_dirs == NULL)
+    {
+      free_split_directories(prog_dirs);
+      return NULL;
+    }
 
   /* Remove the program name from comparison of directory names.  */
   prog_num--;
@@ -365,7 +373,12 @@ make_relative_prefix_1 (const char *progname, const ch
 
   ret = (char *) malloc (needed_len);
   if (ret == NULL)
-    return NULL;
+    {
+      free_split_directories (prog_dirs);
+      free_split_directories (bin_dirs);
+      free_split_directories (prefix_dirs);
+      return NULL;
+    }
 
   /* Build up the pathnames in argv[0].  */
   *ret = '\0';
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to