path UPDATE context not required for freeing
diff --git a/src/path.c b/src/path.c
index f9b04e9..3876762 100644
--- a/src/path.c
+++ b/src/path.c
@@ -1091,7 +1091,7 @@
     }
     lref = (const struct lysc_type_leafref *)deref_leaf_node->type;
     LY_CHECK_GOTO(ret = ly_path_append(ctx, path2, path), cleanup);
-    ly_path_free(ctx, path2);
+    ly_path_free(path2);
     path2 = NULL;
 
     /* compile dereferenced leafref expression and append it to the path */
@@ -1099,7 +1099,7 @@
             &path2), cleanup);
     node2 = path2[LY_ARRAY_COUNT(path2) - 1].node;
     LY_CHECK_GOTO(ret = ly_path_append(ctx, path2, path), cleanup);
-    ly_path_free(ctx, path2);
+    ly_path_free(path2);
     path2 = NULL;
 
     /* properly parsed path must always continue with ')' and '/' */
@@ -1123,9 +1123,9 @@
     LY_CHECK_GOTO(ret = ly_path_append(ctx, path2, path), cleanup);
 
 cleanup:
-    ly_path_free(ctx, path2);
+    ly_path_free(path2);
     if (ret) {
-        ly_path_free(ctx, *path);
+        ly_path_free(*path);
         *path = NULL;
     }
     return ret;
@@ -1281,7 +1281,7 @@
 
 cleanup:
     if (ret) {
-        ly_path_free(ctx, *path);
+        ly_path_free(*path);
         *path = NULL;
     }
     LOG_LOCBACK(cur_node ? 1 : 0, 0);
@@ -1486,7 +1486,7 @@
 }
 
 void
-ly_path_free(const struct ly_ctx *ctx, struct ly_path *path)
+ly_path_free(struct ly_path *path)
 {
     LY_ARRAY_COUNT_TYPE u;
 
@@ -1495,7 +1495,7 @@
     }
 
     LY_ARRAY_FOR(path, u) {
-        ly_path_predicates_free(ctx, path[u].predicates);
+        ly_path_predicates_free(path[u].node->module->ctx, path[u].predicates);
     }
     LY_ARRAY_FREE(path);
 }
diff --git a/src/path.h b/src/path.h
index 9a9e342..68cf76e 100644
--- a/src/path.h
+++ b/src/path.h
@@ -257,9 +257,8 @@
 /**
  * @brief Free ly_path structure.
  *
- * @param[in] ctx libyang context.
  * @param[in] path The structure ([sized array](@ref sizedarrays)) to free.
  */
-void ly_path_free(const struct ly_ctx *ctx, struct ly_path *path);
+void ly_path_free(struct ly_path *path);
 
 #endif /* LY_PATH_H_ */
diff --git a/src/plugins_types.c b/src/plugins_types.c
index 39884e2..3373b0b 100644
--- a/src/plugins_types.c
+++ b/src/plugins_types.c
@@ -895,7 +895,7 @@
             ly_err_clean((struct ly_ctx *)ctx, e);
         }
 
-        ly_path_free(ctx, *path);
+        ly_path_free(*path);
         *path = NULL;
     }
 
@@ -903,9 +903,9 @@
 }
 
 LIBYANG_API_DEF void
-lyplg_type_lypath_free(const struct ly_ctx *ctx, struct ly_path *path)
+lyplg_type_lypath_free(const struct ly_ctx *UNUSED(ctx), struct ly_path *path)
 {
-    ly_path_free(ctx, path);
+    ly_path_free(path);
 }
 
 LIBYANG_API_DEF LY_ERR
@@ -1014,7 +1014,7 @@
     LY_CHECK_GOTO(lyxp_expr_parse(ctx_node->module->ctx, str_path, 0, 1, target_path), cleanup);
 
 cleanup:
-    ly_path_free(ctx_node->module->ctx, p);
+    ly_path_free(p);
     free(str_path);
     return rc;
 }
diff --git a/src/plugins_types/instanceid.c b/src/plugins_types/instanceid.c
index b903b6f..c23ddb5 100644
--- a/src/plugins_types/instanceid.c
+++ b/src/plugins_types/instanceid.c
@@ -307,7 +307,7 @@
 {
     lydict_remove(ctx, value->_canonical);
     value->_canonical = NULL;
-    ly_path_free(ctx, value->target);
+    ly_path_free(value->target);
 }
 
 /**
diff --git a/src/schema_compile.c b/src/schema_compile.c
index bda517c..fde3128 100644
--- a/src/schema_compile.c
+++ b/src/schema_compile.c
@@ -866,7 +866,7 @@
 
     /* get the target node */
     target = p[LY_ARRAY_COUNT(p) - 1].node;
-    ly_path_free(node->module->ctx, p);
+    ly_path_free(p);
 
     if (!(target->nodetype & (LYS_LEAF | LYS_LEAFLIST))) {
         LOGVAL(ctx->ctx, LYVE_REFERENCE, "Invalid leafref path \"%s\" - target node is %s instead of leaf or leaf-list.",
@@ -1456,7 +1456,7 @@
             ret = ly_path_compile_leafref(cctx.ctx, l->node, cctx.ext, lref->path,
                     (l->node->flags & LYS_IS_OUTPUT) ? LY_PATH_OPER_OUTPUT : LY_PATH_OPER_INPUT, LY_PATH_TARGET_MANY,
                     LY_VALUE_SCHEMA_RESOLVED, lref->prefixes, &path);
-            ly_path_free(l->node->module->ctx, path);
+            ly_path_free(path);
 
             assert(ret != LY_ERECOMPILE);
             if (ret) {
diff --git a/src/tree_data.c b/src/tree_data.c
index d968205..a8c42bf 100644
--- a/src/tree_data.c
+++ b/src/tree_data.c
@@ -3595,7 +3595,7 @@
 
 cleanup:
     lyxp_expr_free(LYD_CTX(ctx_node), expr);
-    ly_path_free(LYD_CTX(ctx_node), lypath);
+    ly_path_free(lypath);
     return ret;
 }
 
diff --git a/src/tree_data_new.c b/src/tree_data_new.c
index 792e019..7b26508 100644
--- a/src/tree_data_new.c
+++ b/src/tree_data_new.c
@@ -1823,7 +1823,7 @@
             LY_ARRAY_INCREMENT(p);
         }
     }
-    ly_path_free(ctx, p);
+    ly_path_free(p);
     if (!ret) {
         /* set out params only on success */
         if (new_parent) {
diff --git a/src/tree_schema.c b/src/tree_schema.c
index d7ac8d8..81bda1b 100644
--- a/src/tree_schema.c
+++ b/src/tree_schema.c
@@ -644,7 +644,7 @@
     ret = lys_find_lypath_atoms(p, set);
 
 cleanup:
-    ly_path_free(ctx, p);
+    ly_path_free(p);
     lyxp_expr_free(ctx, expr);
     return ret;
 }
@@ -679,7 +679,7 @@
     snode = p[LY_ARRAY_COUNT(p) - 1].node;
 
 cleanup:
-    ly_path_free(ctx, p);
+    ly_path_free(p);
     lyxp_expr_free(ctx, expr);
     return snode;
 }
diff --git a/src/tree_schema_common.c b/src/tree_schema_common.c
index dcfb096..0faaa3c 100644
--- a/src/tree_schema_common.c
+++ b/src/tree_schema_common.c
@@ -1829,7 +1829,7 @@
 
     /* get the target node */
     target = p[LY_ARRAY_COUNT(p) - 1].node;
-    ly_path_free(node->module->ctx, p);
+    ly_path_free(p);
 
     return target;
 }
diff --git a/src/xpath.c b/src/xpath.c
index 0b3062f..2251eab 100644
--- a/src/xpath.c
+++ b/src/xpath.c
@@ -4042,7 +4042,7 @@
             if (!r) {
                 /* get the target node */
                 target = p[LY_ARRAY_COUNT(p) - 1].node;
-                ly_path_free(set->ctx, p);
+                ly_path_free(p);
 
                 LY_CHECK_RET(lyxp_set_scnode_insert_node(set, target, LYXP_NODE_ELEM, LYXP_AXIS_SELF, NULL));
             } /* else the target was found before but is disabled so it was removed */
@@ -8272,7 +8272,9 @@
         options &= ~LYXP_SKIP_EXPR;
     }
     lydict_remove(set->ctx, ncname_dict);
-    ly_path_predicates_free(set->ctx, predicates);
+    if (predicates) {
+        ly_path_predicates_free(scnode->module->ctx, predicates);
+    }
     return rc;
 }
 
diff --git a/tests/utests/data/test_tree_data.c b/tests/utests/data/test_tree_data.c
index fabd170..b3dde5a 100644
--- a/tests/utests/data/test_tree_data.c
+++ b/tests/utests/data/test_tree_data.c
@@ -409,7 +409,7 @@
     assert_string_equal(lyd_get_value(term->prev), "b");
 
     lyd_free_all(tree);
-    ly_path_free(UTEST_LYCTX, path);
+    ly_path_free(path);
     lyxp_expr_free(UTEST_LYCTX, exp);
 }