From: Namhyung Kim Date: Mon, 30 Jun 2014 15:12:42 +0000 (+0900) Subject: chcon: avoid redundant context allocations X-Git-Tag: v8.23~26 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3106de5c789834cc9ee01fbc27b83b217e45e2ef;p=thirdparty%2Fcoreutils.git 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. --- diff --git a/src/chcon.c b/src/chcon.c index 8c18167ffb..6940cf54eb 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; }