]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
maint: make chmod/chgrp/chown leak free under valgrind
authorPádraig Brady <P@draigBrady.com>
Mon, 14 May 2018 01:52:25 +0000 (18:52 -0700)
committerPádraig Brady <P@draigBrady.com>
Tue, 15 May 2018 06:51:13 +0000 (23:51 -0700)
* src/chmod.c: Deallocate the mode change array in dev mode.
* src/chown.c: Make chopt_free() actually deallocate, but
only call in dev mode.
* src/chgrp.c: Likewise.

src/chgrp.c
src/chmod.c
src/chown-core.c
src/chown-core.h
src/chown.c

index 130fa73ddc3ff92d1581a56ed502992bb50ed107..ec3bb13b7b9488fb3903db2302aa368995b0ef51 100644 (file)
@@ -295,7 +295,7 @@ main (int argc, char **argv)
   else
     {
       char *group_name = argv[optind++];
-      chopt.group_name = (*group_name ? group_name : NULL);
+      chopt.group_name = (*group_name ? xstrdup (group_name) : NULL);
       gid = parse_group (group_name);
     }
 
@@ -313,7 +313,7 @@ main (int argc, char **argv)
                     (uid_t) -1, gid,
                     (uid_t) -1, (gid_t) -1, &chopt);
 
-  chopt_free (&chopt);
+  IF_LINT (chopt_free (&chopt));
 
   return ok ? EXIT_SUCCESS : EXIT_FAILURE;
 }
index 0e9436c7285f6bbf44cc10f2d14e2899fe32605a..520d5e11a9acfbd6b4e76539809232e149f06a96 100644 (file)
@@ -566,5 +566,7 @@ main (int argc, char **argv)
   ok = process_files (argv + optind,
                       FTS_COMFOLLOW | FTS_PHYSICAL | FTS_DEFER_STAT);
 
+  IF_LINT (free (change));
+
   return ok ? EXIT_SUCCESS : EXIT_FAILURE;
 }
index c235ef39165cb85f42b6aa31c7af561ed476562f..c99d263f25a44e35362be4b48298adcea7eb3981 100644 (file)
@@ -66,6 +66,13 @@ chopt_init (struct Chown_option *chopt)
   chopt->group_name = NULL;
 }
 
+extern void
+chopt_free (struct Chown_option *chopt)
+{
+  free (chopt->user_name);
+  free (chopt->group_name);
+}
+
 /* Convert the numeric group-id, GID, to a string stored in xmalloc'd memory,
    and return it.  If there's no corresponding group name, use the decimal
    representation of the ID.  */
index c410158a6f9e56bc327d10daee0c2a99a5acd3be..77a5febd409eb358f9f5d98612fd4ae7187991ab 100644 (file)
@@ -68,9 +68,8 @@ struct Chown_option
 void
 chopt_init (struct Chown_option *);
 
-/* Deliberately do not free chopt->user_name or ->group_name.
-   They're not always allocated.  */
-# define chopt_free(chopt)
+void
+chopt_free (struct Chown_option *);
 
 char *
 gid_to_name (gid_t) _GL_ATTRIBUTE_MALLOC;
index da6ed4ab4d575056cb73461629b9b09b930ae4b5..f44eab2f5efbb30f436039e39d7a451c8b75d896 100644 (file)
@@ -306,7 +306,7 @@ main (int argc, char **argv)
          empty string so that diagnostics say "ownership :GROUP"
          rather than "group GROUP".  */
       if (!chopt.user_name && chopt.group_name)
-        chopt.user_name = bad_cast ("");
+        chopt.user_name = xstrdup ("");
 
       optind++;
     }
@@ -325,7 +325,7 @@ main (int argc, char **argv)
                     uid, gid,
                     required_uid, required_gid, &chopt);
 
-  chopt_free (&chopt);
+  IF_LINT (chopt_free (&chopt));
 
   return ok ? EXIT_SUCCESS : EXIT_FAILURE;
 }