]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: improve context deinitialization
authorKarel Zak <kzak@redhat.com>
Wed, 12 Oct 2022 10:23:37 +0000 (12:23 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 3 Jan 2023 11:58:42 +0000 (12:58 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
libmount/src/context.c
libmount/src/hooks.c

index 3551b0d77bcf889ce03aa8425e4c7bf7149fadf0..96f43d58dcb400e31a48089d6842e52b4ceea45c 100644 (file)
@@ -110,11 +110,10 @@ void mnt_free_context(struct libmnt_context *cxt)
        mnt_free_update(cxt->update);
 
        mnt_context_set_target_ns(cxt, NULL);
-       mnt_context_deinit_hooksets(cxt);
 
        free(cxt->children);
 
-       DBG(CXT, ul_debugobj(cxt, "<---- free"));
+       DBG(CXT, ul_debugobj(cxt, "free"));
        free(cxt);
 }
 
@@ -232,12 +231,15 @@ int mnt_context_apply_template(struct libmnt_context *cxt)
        if (!cxt)
                return -EINVAL;
 
-       DBG(CXT, ul_debugobj(cxt, "restoring template"));
-       mnt_unref_optlist(cxt->optlist);
-       cxt->optlist = NULL;
+       if (cxt->optlist) {
+               mnt_unref_optlist(cxt->optlist);
+               cxt->optlist = NULL;
+       }
 
-       if (cxt->optlist_saved)
+       if (cxt->optlist_saved) {
+               DBG(CXT, ul_debugobj(cxt, "restoring template"));
                cxt->optlist = mnt_copy_optlist(cxt->optlist_saved);
+       }
 
        return 0;
 }
@@ -1974,6 +1976,8 @@ int mnt_context_prepare_helper(struct libmnt_context *cxt, const char *name,
        assert(cxt->fs);
        assert((cxt->flags & MNT_FL_MOUNTFLAGS_MERGED));
 
+       DBG(CXT, ul_debugobj(cxt, "checking for helper"));
+
        if (cxt->helper) {
                free(cxt->helper);
                cxt->helper = NULL;
index ef528276928ee9e98305d94db3484b5a504f4a82..7b1ab7f5a24d7100e7441afa6ef6e96efe4e086c 100644 (file)
@@ -92,9 +92,6 @@ int mnt_context_deinit_hooksets(struct libmnt_context *cxt)
 
        assert(cxt);
 
-       if (list_empty(&cxt->hooksets_hooks))
-               return 0;
-
        for (i = 0; i <  ARRAY_SIZE(hooksets); i++) {
                const struct libmnt_hookset *hs = hooksets[i];