xpath BUGFIX invalid pointer dereference
diff --git a/src/xpath.c b/src/xpath.c
index 55cfa2b..38489ee 100644
--- a/src/xpath.c
+++ b/src/xpath.c
@@ -3512,7 +3512,7 @@
 {
     struct lysc_ctx cctx;
     struct lyd_node_term *leaf;
-    struct lysc_node_leaf *sleaf;
+    struct lysc_node_leaf *sleaf = NULL;
     const struct lysc_node *target;
     const struct lyd_node *node;
     char *errmsg = NULL;
@@ -3530,7 +3530,7 @@
                    __func__, sleaf->name);
         }
         set_scnode_clear_ctx(set);
-        if ((rc == LY_SUCCESS) && (sleaf->type->basetype == LY_TYPE_LEAFREF)) {
+        if (sleaf && (sleaf->type->basetype == LY_TYPE_LEAFREF)) {
             cctx.ctx = set->ctx;
             rc = lys_compile_leafref_validate(&cctx, (struct lysc_node *)sleaf, (struct lysc_type_leafref *)sleaf->type, &target);
             /* it was already validated, it must succeed */