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 <liwugang@xiaomi.com>
This commit is contained in:
liwugang 2019-07-01 14:52:18 +08:00
parent 56d34f7838
commit 85ce153283

View file

@ -65,14 +65,15 @@ static int read_cil_file(struct cil_db **db, char *path) {
rc = cil_add_file(*db, path, buff, file_size); rc = cil_add_file(*db, path, buff, file_size);
if (rc != SEPOL_OK) { if (rc != SEPOL_OK) {
fprintf(stderr, "Failure adding %s to parse tree\n", path); fprintf(stderr, "Failure adding %s to parse tree\n", path);
goto err; goto parse_err;
} }
free(buff); free(buff);
return SEPOL_OK; return SEPOL_OK;
err: err:
free(buff);
fclose(file); fclose(file);
parse_err:
free(buff);
file_err: file_err:
cil_db_destroy(db); cil_db_destroy(db);
return rc; return rc;