data tree BUGFIX set out param
diff --git a/src/tree_data.c b/src/tree_data.c
index 81d7744..14719a7 100644
--- a/src/tree_data.c
+++ b/src/tree_data.c
@@ -978,6 +978,9 @@
         LOGERR(ctx, LY_EINVAL, "Cannot add metadata to an opaque node \"%s\".", ((struct lyd_node_opaq *)parent)->name);
         return LY_EINVAL;
     }
+    if (meta) {
+        *meta = NULL;
+    }
 
     /* parse the name */
     tmp = name;
@@ -1013,6 +1016,9 @@
         LOGERR(ctx, LY_EINVAL, "Cannot add metadata to an opaque node \"%s\".", ((struct lyd_node_opaq *)parent)->name);
         return LY_EINVAL;
     }
+    if (meta) {
+        *meta = NULL;
+    }
 
     switch (attr->format) {
     case LY_PREF_XML: