mirror of
https://github.com/SELinuxProject/selinux
synced 2025-02-01 10:21:52 +00:00
libselinux/utils: free allocated resources
Remove noise while running with sanitizers or under valgrind. Signed-off-by: Christian Göttsche <cgzones@googlemail.com> Acked-by: James Carter <jwcart2@gmail.com>
This commit is contained in:
parent
abd18ec31b
commit
1d5c3b7204
@ -19,8 +19,9 @@ static __attribute__ ((__noreturn__)) void usage(const char *name, const char *d
|
|||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
char **list, *cur_context = NULL;
|
char **list;
|
||||||
char *user = NULL, *level = NULL;
|
const char *cur_context, *user;
|
||||||
|
char *cur_con = NULL, *level = NULL;
|
||||||
int ret, i, opt;
|
int ret, i, opt;
|
||||||
|
|
||||||
while ((opt = getopt(argc, argv, "l:")) > 0) {
|
while ((opt = getopt(argc, argv, "l:")) > 0) {
|
||||||
@ -54,11 +55,12 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
/* If a context wasn't passed, use the current context. */
|
/* If a context wasn't passed, use the current context. */
|
||||||
if (((argc - optind) < 2)) {
|
if (((argc - optind) < 2)) {
|
||||||
if (getcon(&cur_context) < 0) {
|
if (getcon(&cur_con) < 0) {
|
||||||
fprintf(stderr, "Couldn't get current context: %s\n", strerror(errno));
|
fprintf(stderr, "Couldn't get current context: %s\n", strerror(errno));
|
||||||
free(level);
|
free(level);
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
cur_context = cur_con;
|
||||||
} else {
|
} else {
|
||||||
cur_context = argv[optind + 1];
|
cur_context = argv[optind + 1];
|
||||||
if (security_check_context(cur_context) != 0) {
|
if (security_check_context(cur_context) != 0) {
|
||||||
@ -82,10 +84,12 @@ int main(int argc, char **argv)
|
|||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "get_ordered_context_list%s failure: %d(%s)\n",
|
fprintf(stderr, "get_ordered_context_list%s failure: %d(%s)\n",
|
||||||
level ? "_with_level" : "", errno, strerror(errno));
|
level ? "_with_level" : "", errno, strerror(errno));
|
||||||
|
free(cur_con);
|
||||||
free(level);
|
free(level);
|
||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(cur_con);
|
||||||
free(level);
|
free(level);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -19,8 +19,9 @@ static __attribute__ ((__noreturn__)) void usage(const char *name, const char *d
|
|||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
char * usercon = NULL, *cur_context = NULL;
|
const char *cur_context, *user;
|
||||||
char *user = NULL, *level = NULL, *role=NULL, *seuser=NULL, *dlevel=NULL;
|
char *usercon = NULL, *cur_con = NULL;
|
||||||
|
char *level = NULL, *role=NULL, *seuser=NULL, *dlevel=NULL;
|
||||||
char *service = NULL;
|
char *service = NULL;
|
||||||
int ret, opt;
|
int ret, opt;
|
||||||
int verbose = 0;
|
int verbose = 0;
|
||||||
@ -54,6 +55,9 @@ int main(int argc, char **argv)
|
|||||||
if (!is_selinux_enabled()) {
|
if (!is_selinux_enabled()) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"%s may be used only on a SELinux kernel.\n", argv[0]);
|
"%s may be used only on a SELinux kernel.\n", argv[0]);
|
||||||
|
free(level);
|
||||||
|
free(role);
|
||||||
|
free(service);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,15 +65,23 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
/* If a context wasn't passed, use the current context. */
|
/* If a context wasn't passed, use the current context. */
|
||||||
if ((argc - optind) < 2) {
|
if ((argc - optind) < 2) {
|
||||||
if (getcon(&cur_context) < 0) {
|
if (getcon(&cur_con) < 0) {
|
||||||
fprintf(stderr, "%s: couldn't get current context: %s\n", argv[0], strerror(errno));
|
fprintf(stderr, "%s: couldn't get current context: %s\n", argv[0], strerror(errno));
|
||||||
|
free(level);
|
||||||
|
free(role);
|
||||||
|
free(service);
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
cur_context = cur_con;
|
||||||
} else
|
} else
|
||||||
cur_context = argv[optind + 1];
|
cur_context = argv[optind + 1];
|
||||||
|
|
||||||
if (security_check_context(cur_context)) {
|
if (security_check_context(cur_context)) {
|
||||||
fprintf(stderr, "%s: invalid from context '%s'\n", argv[0], cur_context);
|
fprintf(stderr, "%s: invalid from context '%s'\n", argv[0], cur_context);
|
||||||
|
free(cur_con);
|
||||||
|
free(level);
|
||||||
|
free(role);
|
||||||
|
free(service);
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,6 +113,8 @@ out:
|
|||||||
if (level != dlevel) free(level);
|
if (level != dlevel) free(level);
|
||||||
free(dlevel);
|
free(dlevel);
|
||||||
free(usercon);
|
free(usercon);
|
||||||
|
free(cur_con);
|
||||||
|
free(service);
|
||||||
|
|
||||||
return ret >= 0;
|
return ret >= 0;
|
||||||
}
|
}
|
||||||
|
@ -45,6 +45,7 @@ int main(int argc, char **argv)
|
|||||||
con = strdup(argv[2]);
|
con = strdup(argv[2]);
|
||||||
if (security_check_context(con)) {
|
if (security_check_context(con)) {
|
||||||
fprintf(stderr, "%s: invalid from context '%s'\n", argv[0], con);
|
fprintf(stderr, "%s: invalid from context '%s'\n", argv[0], con);
|
||||||
|
free(con);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user