path UPDATE context not required for freeing
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;
 }