From e0db1651e6444a62cf76b9792caf0f11d76fc864 Mon Sep 17 00:00:00 2001 From: Chih-Hung Hsieh Date: Fri, 31 Aug 2018 10:11:09 -0700 Subject: [PATCH] Free type_rules before return or exit. Test: make with WITH_TIDY=1 and clang-analyzer-* checks. Change-Id: Ide1eaf8880132c566545710e6287f66a5a2b393c --- tools/sepolicy-analyze/typecmp.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tools/sepolicy-analyze/typecmp.c b/tools/sepolicy-analyze/typecmp.c index 5fffd6379..c00c13c23 100644 --- a/tools/sepolicy-analyze/typecmp.c +++ b/tools/sepolicy-analyze/typecmp.c @@ -174,26 +174,33 @@ static int analyze_types(policydb_t * policydb, char diff, char equiv) if (avtab_init(&exp_avtab) || avtab_init(&exp_cond_avtab)) { fputs("out of memory\n", stderr); + free(type_rules); return -1; } if (expand_avtab(policydb, &policydb->te_avtab, &exp_avtab)) { fputs("out of memory\n", stderr); avtab_destroy(&exp_avtab); + free(type_rules); return -1; } if (expand_avtab(policydb, &policydb->te_cond_avtab, &exp_cond_avtab)) { fputs("out of memory\n", stderr); avtab_destroy(&exp_avtab); /* */ + free(type_rules); return -1; } - if (avtab_map(&exp_avtab, create_type_rules, type_rules)) + if (avtab_map(&exp_avtab, create_type_rules, type_rules)) { + free(type_rules); exit(1); + } - if (avtab_map(&exp_cond_avtab, create_type_rules_cond, type_rules)) + if (avtab_map(&exp_cond_avtab, create_type_rules_cond, type_rules)) { + free(type_rules); exit(1); + } avtab_destroy(&exp_avtab); avtab_destroy(&exp_cond_avtab);