data tree BUGFIX new top-level nodes need parent or ret value

Otherwise they would leak.
diff --git a/src/tree_data.c b/src/tree_data.c
index 7780c97..2047fe2 100644
--- a/src/tree_data.c
+++ b/src/tree_data.c
@@ -664,7 +664,7 @@
     const struct lysc_node *schema;
     struct ly_ctx *ctx = parent ? parent->schema->module->ctx : (module ? module->ctx : NULL);
 
-    LY_CHECK_ARG_RET(ctx, parent || module, name, LY_EINVAL);
+    LY_CHECK_ARG_RET(ctx, parent || module, parent || node, name, LY_EINVAL);
 
     if (!module) {
         module = parent->schema->module;
@@ -695,7 +695,7 @@
     const char *key_val;
     LY_ERR rc = LY_SUCCESS;
 
-    LY_CHECK_ARG_RET(ctx, parent || module, name, LY_EINVAL);
+    LY_CHECK_ARG_RET(ctx, parent || module, parent || node, name, LY_EINVAL);
 
     if (!module) {
         module = parent->schema->module;
@@ -742,7 +742,7 @@
     const struct lysc_node *schema;
     struct ly_ctx *ctx = parent ? parent->schema->module->ctx : (module ? module->ctx : NULL);
 
-    LY_CHECK_ARG_RET(ctx, parent || module, name, LY_EINVAL);
+    LY_CHECK_ARG_RET(ctx, parent || module, parent || node, name, LY_EINVAL);
 
     if (!module) {
         module = parent->schema->module;
@@ -781,7 +781,7 @@
     const struct lysc_node *schema;
     struct ly_ctx *ctx = parent ? parent->schema->module->ctx : (module ? module->ctx : NULL);
 
-    LY_CHECK_ARG_RET(ctx, parent || module, name, LY_EINVAL);
+    LY_CHECK_ARG_RET(ctx, parent || module, parent || node, name, LY_EINVAL);
 
     if (!module) {
         module = parent->schema->module;
@@ -810,7 +810,7 @@
     const struct lysc_node *schema;
     struct ly_ctx *ctx = parent ? parent->schema->module->ctx : (module ? module->ctx : NULL);
 
-    LY_CHECK_ARG_RET(ctx, parent || module, name, LY_EINVAL);
+    LY_CHECK_ARG_RET(ctx, parent || module, parent || node, name, LY_EINVAL);
 
     if (!module) {
         module = parent->schema->module;
@@ -952,7 +952,7 @@
 {
     struct lyd_node *ret = NULL;
 
-    LY_CHECK_ARG_RET(ctx, parent || ctx, name, module_name, LY_EINVAL);
+    LY_CHECK_ARG_RET(ctx, parent || ctx, parent || node, name, module_name, LY_EINVAL);
 
     if (!ctx) {
         ctx = LYD_NODE_CTX(parent);
diff --git a/tests/utests/data/test_new.c b/tests/utests/data/test_new.c
index c9c32f8..21eb126 100644
--- a/tests/utests/data/test_new.c
+++ b/tests/utests/data/test_new.c
@@ -118,13 +118,13 @@
     assert_int_equal(lyd_new_list2(NULL, mod, "l1", "[]", &node), LY_EVALID);
     logbuf_assert("Unexpected XPath token ] (]).");
 
-    assert_int_equal(lyd_new_list2(NULL, mod, "l1", "[key1='a'][key2='b']", NULL), LY_ENOTFOUND);
+    assert_int_equal(lyd_new_list2(NULL, mod, "l1", "[key1='a'][key2='b']", &node), LY_ENOTFOUND);
     logbuf_assert("Not found node \"key1\" in path.");
 
-    assert_int_equal(lyd_new_list2(NULL, mod, "l1", "[a='a'][b='b'][c='c']", NULL), LY_EVALID);
+    assert_int_equal(lyd_new_list2(NULL, mod, "l1", "[a='a'][b='b'][c='c']", &node), LY_EVALID);
     logbuf_assert("Key expected instead of leaf \"c\" in path. /a:l1/c");
 
-    assert_int_equal(lyd_new_list2(NULL, mod, "c", "[a='a'][b='b']", NULL), LY_ENOTFOUND);
+    assert_int_equal(lyd_new_list2(NULL, mod, "c", "[a='a'][b='b']", &node), LY_ENOTFOUND);
     logbuf_assert("List node \"c\" not found.");
 
     assert_int_equal(lyd_new_list2(NULL, mod, "l1", "[a='a'][b='b']", &node), LY_SUCCESS);
@@ -140,10 +140,10 @@
     lyd_free_tree(node);
 
     /* leaf */
-    assert_int_equal(lyd_new_term(NULL, mod, "foo", "[a='a'][b='b'][c='c']", NULL), LY_EVALID);
+    assert_int_equal(lyd_new_term(NULL, mod, "foo", "[a='a'][b='b'][c='c']", &node), LY_EVALID);
     logbuf_assert("Invalid uint16 value \"[a='a'][b='b'][c='c']\". /a:foo");
 
-    assert_int_equal(lyd_new_term(NULL, mod, "c", "value", NULL), LY_ENOTFOUND);
+    assert_int_equal(lyd_new_term(NULL, mod, "c", "value", &node), LY_ENOTFOUND);
     logbuf_assert("Term node \"c\" not found.");
 
     assert_int_equal(lyd_new_term(NULL, mod, "foo", "256", &node), LY_SUCCESS);
@@ -157,10 +157,10 @@
     assert_int_equal(lyd_new_inner(NULL, mod, "c", &node), LY_SUCCESS);
     lyd_free_tree(node);
 
-    assert_int_equal(lyd_new_inner(NULL, mod, "l1", NULL), LY_ENOTFOUND);
+    assert_int_equal(lyd_new_inner(NULL, mod, "l1", &node), LY_ENOTFOUND);
     logbuf_assert("Inner node (and not a list) \"l1\" not found.");
 
-    assert_int_equal(lyd_new_inner(NULL, mod, "l2", NULL), LY_ENOTFOUND);
+    assert_int_equal(lyd_new_inner(NULL, mod, "l2", &node), LY_ENOTFOUND);
     logbuf_assert("Inner node (and not a list) \"l2\" not found.");
 
     /* anydata */
@@ -168,7 +168,7 @@
     lyd_free_tree(node);
 
     /* key-less list */
-    assert_int_equal(lyd_new_list2(NULL, mod, "l2", "[a='a'][b='b']", NULL), LY_EVALID);
+    assert_int_equal(lyd_new_list2(NULL, mod, "l2", "[a='a'][b='b']", &node), LY_EVALID);
     logbuf_assert("List predicate defined for keyless list \"l2\" in path.");
 
     assert_int_equal(lyd_new_list2(NULL, mod, "l2", "", &node), LY_SUCCESS);