summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNamhyung Kim <namhyung@gmail.com>2014-07-01 00:12:42 +0900
committerPádraig Brady <P@draigBrady.com>2014-07-01 15:45:53 +0100
commit3106de5c789834cc9ee01fbc27b83b217e45e2ef (patch)
tree5b16bfa091bd6684b440990e46987471b260c598
parente4081e44e0dcc4bfe11d0da0ae47518df087349d (diff)
downloadcoreutils-3106de5c789834cc9ee01fbc27b83b217e45e2ef.tar.gz
chcon: avoid redundant context allocations
Since context is verified by security_check_context() it can be used in change_file_context() without converting to context_t every time. * src/chcon.c (change_file_context): Use specified_context directly.
-rw-r--r--src/chcon.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/chcon.c b/src/chcon.c
index 8c18167ff..6940cf54e 100644
--- a/src/chcon.c
+++ b/src/chcon.c
@@ -141,7 +141,7 @@ static int
change_file_context (int fd, char const *file)
{
security_context_t file_context = NULL;
- context_t context;
+ context_t context IF_LINT (= NULL);
security_context_t context_string;
int errors = 0;
@@ -170,17 +170,14 @@ change_file_context (int fd, char const *file)
if (compute_context_from_mask (file_context, &context))
return 1;
+
+ context_string = context_str (context);
}
else
{
- /* FIXME: this should be done exactly once, in main. */
- context = context_new (specified_context);
- if (!context)
- abort ();
+ context_string = specified_context;
}
- context_string = context_str (context);
-
if (file_context == NULL || ! STREQ (context_string, file_context))
{
int fail = (affect_symlink_referent
@@ -195,8 +192,11 @@ change_file_context (int fd, char const *file)
}
}
- context_free (context);
- freecon (file_context);
+ if (specified_context == NULL)
+ {
+ context_free (context);
+ freecon (file_context);
+ }
return errors;
}