diff --git a/libselinux/src/label.c b/libselinux/src/label.c index d2e703ef..06d743ec 100644 --- a/libselinux/src/label.c +++ b/libselinux/src/label.c @@ -225,10 +225,7 @@ struct selabel_handle *selabel_open(unsigned int backend, rec->digest = selabel_is_digest_set(opts, nopts); if ((*initfuncs[backend])(rec, opts, nopts)) { - if (rec->digest) - selabel_digest_fini(rec->digest); - free(rec->spec_file); - free(rec); + selabel_close(rec); rec = NULL; } diff --git a/libselinux/src/label_backends_android.c b/libselinux/src/label_backends_android.c index 33a17236..49a87686 100644 --- a/libselinux/src/label_backends_android.c +++ b/libselinux/src/label_backends_android.c @@ -246,6 +246,9 @@ static void closef(struct selabel_handle *rec) struct spec *spec; unsigned int i; + if (!data) + return; + for (i = 0; i < data->nspec; i++) { spec = &data->spec_arr[i]; free(spec->property_key); diff --git a/libselinux/src/label_db.c b/libselinux/src/label_db.c index 2ff10b2f..40d5fc4a 100644 --- a/libselinux/src/label_db.c +++ b/libselinux/src/label_db.c @@ -178,6 +178,9 @@ db_close(struct selabel_handle *rec) spec_t *spec; unsigned int i; + if (!catalog) + return; + for (i = 0; i < catalog->nspec; i++) { spec = &catalog->specs[i]; free(spec->key); diff --git a/libselinux/src/label_file.c b/libselinux/src/label_file.c index 3b2bda97..2732972e 100644 --- a/libselinux/src/label_file.c +++ b/libselinux/src/label_file.c @@ -904,6 +904,9 @@ static void closef(struct selabel_handle *rec) struct stem *stem; unsigned int i; + if (!data) + return; + selabel_subs_fini(data->subs); selabel_subs_fini(data->dist_subs); diff --git a/libselinux/src/label_media.c b/libselinux/src/label_media.c index fad5ea6d..94a58062 100644 --- a/libselinux/src/label_media.c +++ b/libselinux/src/label_media.c @@ -167,6 +167,9 @@ static void close(struct selabel_handle *rec) struct spec *spec, *spec_arr = data->spec_arr; unsigned int i; + if (!data) + return; + for (i = 0; i < data->nspec; i++) { spec = &spec_arr[i]; free(spec->key); diff --git a/libselinux/src/label_x.c b/libselinux/src/label_x.c index bf569ca5..f994eefa 100644 --- a/libselinux/src/label_x.c +++ b/libselinux/src/label_x.c @@ -194,6 +194,9 @@ static void close(struct selabel_handle *rec) struct spec *spec, *spec_arr = data->spec_arr; unsigned int i; + if (!data) + return; + for (i = 0; i < data->nspec; i++) { spec = &spec_arr[i]; free(spec->key);