schema compile BUGFIX leafref non-prefixed node module

... should be the same as the context node, not
current module, which is only for schema paths.
Made current module in leafref redundant and some
other minor refactoring was added.

Fixes sysrepo/sysrepo#2481
diff --git a/src/schema_compile.c b/src/schema_compile.c
index c2f120e..80996ad 100644
--- a/src/schema_compile.c
+++ b/src/schema_compile.c
@@ -1003,8 +1003,8 @@
 
     assert(node->nodetype & (LYS_LEAF | LYS_LEAFLIST));
 
-    /* try to find the target */
-    LY_CHECK_RET(ly_path_compile(ctx->ctx, lref->cur_mod, node, NULL, lref->path, LY_PATH_LREF_TRUE,
+    /* try to find the target, current module is that of the context node (RFC 7950 6.4.1 second bullet) */
+    LY_CHECK_RET(ly_path_compile_leafref(ctx->ctx, node, NULL, lref->path,
             (node->flags & LYS_IS_OUTPUT) ? LY_PATH_OPER_OUTPUT : LY_PATH_OPER_INPUT, LY_PATH_TARGET_MANY,
             LY_VALUE_SCHEMA_RESOLVED, lref->prefixes, unres, &p));