mirror of
https://git.savannah.gnu.org/git/coreutils.git
synced 2026-11-17 18:02:09 +03:00
maint: make chmod/chgrp/chown leak free under valgrind
* 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.
This commit is contained in:
1 parent
a5d158ab8f
commit
694d10b71e
5 files changed
+15
-7
No files matched your search
+2
-2
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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. */
|
||||
|
||||
+2
-3
@@ -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;
|
||||
|
||||
+2
-2
@@ -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;
|
||||
}
|
||||
Reference in new issue
Block a user