From 85ce1532839289fcd56de3bebb2390ebfee7e001 Mon Sep 17 00:00:00 2001 From: liwugang Date: Mon, 1 Jul 2019 14:52:18 +0800 Subject: [PATCH] version_policy: avoid fclose a NULL file pointer Test: Pass a not cil file to version_policy and see no crash appeared. example: out/host/linux-x86/bin/version_policy -b `which ls` -m -n 10000.0 -o target Change-Id: If2b950a02dd94a4813b74377617f90c7a75a9f27 Signed-off-by: liwugang --- tools/version_policy.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/version_policy.c b/tools/version_policy.c index 8848190a9..8bb422af6 100644 --- a/tools/version_policy.c +++ b/tools/version_policy.c @@ -65,14 +65,15 @@ static int read_cil_file(struct cil_db **db, char *path) { rc = cil_add_file(*db, path, buff, file_size); if (rc != SEPOL_OK) { fprintf(stderr, "Failure adding %s to parse tree\n", path); - goto err; + goto parse_err; } free(buff); return SEPOL_OK; err: - free(buff); fclose(file); +parse_err: + free(buff); file_err: cil_db_destroy(db); return rc;