OSDN Git Service

* cygpath.cc: Throughout, free obsolete path buffers.
authorcorinna <corinna>
Fri, 8 Jan 2010 02:19:12 +0000 (02:19 +0000)
committercorinna <corinna>
Fri, 8 Jan 2010 02:19:12 +0000 (02:19 +0000)
winsup/utils/ChangeLog
winsup/utils/cygpath.cc

index e3bab28..a8438b5 100644 (file)
@@ -1,5 +1,9 @@
 2010-01-07  Corinna Vinschen  <corinna@vinschen.de>
 
+       * cygpath.cc: Throughout, free obsolete path buffers.
+
+2010-01-07  Corinna Vinschen  <corinna@vinschen.de>
+
        * cygpath.cc (main): Remove enforcing "en_US.UTF-8" locale.
        Revert usage of argz functions when reading input from file and
        simplify option usage.  Allow only one option argument and use
index 6af5d0d..8790031 100644 (file)
@@ -29,7 +29,7 @@ details. */
 #include <ddk/ntifs.h>
 #include "wide_path.h"
 
-static const char version[] = "$Revision: 1.57 $";
+static const char version[] = "$Revision: 1.58 $";
 
 static char *prog_name;
 static char *file_arg, *output_arg;
@@ -226,6 +226,7 @@ get_device_name (char *path)
                 a valid DOS device name, if prepended with "\\.\".  Return that
                 valid DOS path. */
              ULONG len = RtlUnicodeStringToAnsiSize (&odi->ObjectName);
+             free (ret);
              ret = (char *) malloc (len + 4);
              strcpy (ret, "\\\\.\\");
              ans.Length = 0;
@@ -666,10 +667,18 @@ do_sysfolders (char option)
     }
   else
     {
+      char *tmp;
+
       if (shortname_flag)
-       buf = get_short_name (buf);
+       {
+         buf = get_short_name (tmp = buf);
+         free (tmp);
+       }
       if (mixed_flag)
-       buf = get_mixed_name (buf);
+       {
+         buf = get_mixed_name (tmp = buf);
+         free (tmp);
+       }
     }
   printf ("%s\n", buf);
 }
@@ -695,8 +704,8 @@ report_mode (char *filename)
 static void
 do_pathconv (char *filename)
 {
-  char *buf;
-  wchar_t *buf2;
+  char *buf = NULL, *tmp;
+  wchar_t *buf2 = NULL;
   DWORD len;
   ssize_t err;
   cygwin_conv_path_t conv_func =
@@ -737,13 +746,23 @@ do_pathconv (char *filename)
        {
          if (err)
            /* oops */;
-         buf = get_device_paths (buf);
+         buf = get_device_paths (tmp = buf);
+         free (tmp);
          if (shortname_flag)
-           buf = get_short_paths (buf);
+           {
+             buf = get_short_paths (tmp = buf);
+             free (tmp);
+           }
          if (longname_flag)
-           buf = get_long_paths (buf);
+           {
+             buf = get_long_paths (tmp = buf);
+             free (tmp);
+           }
          if (mixed_flag)
-           buf = get_mixed_name (buf);
+           {
+             buf = get_mixed_name (tmp = buf);
+             free (tmp);
+           }
        }
       if (err)
        {
@@ -765,11 +784,21 @@ do_pathconv (char *filename)
       if (!unix_flag)
        {
          my_wcstombs (buf, buf2, 32768);
-         buf = get_device_name (buf);
+         buf = get_device_name (tmp = buf);
+         free (tmp);
          if (shortname_flag)
-           buf = get_short_name (buf);
+           {
+             buf = get_short_name (tmp = buf);
+             free (tmp);
+           }
          if (longname_flag)
-           buf = get_long_name (buf, len);
+           {
+             buf = get_long_name (tmp = buf, len);
+             free (tmp);
+           }
+         /* buf gets moved into the array so we have to set tmp for later
+            freeing beforehand. */
+         tmp = buf;
          if (strncmp (buf, "\\\\?\\", 4) == 0)
            {
              len = 4;
@@ -783,11 +812,18 @@ do_pathconv (char *filename)
                }
            }
          if (mixed_flag)
-           buf = get_mixed_name (buf);
+           {
+             buf = get_mixed_name (buf);
+             free (tmp);
+           }
        }
     }
 
   puts (buf);
+  if (buf2)
+    free (buf2);
+  if (buf)
+    free (buf);
 }
 
 static void