tree data BUGFIX simplify value freeing

Refs #1837
diff --git a/src/tree_data.c b/src/tree_data.c
index 4f5f97a..3003b4e 100644
--- a/src/tree_data.c
+++ b/src/tree_data.c
@@ -1587,7 +1587,7 @@
     struct lysc_type *type;
     struct lyd_node_term *t;
     struct lyd_node *parent;
-    struct lyd_value val = {0};
+    struct lyd_value val;
     ly_bool dflt_change, val_change;
 
     assert(term && term->schema && (term->schema->nodetype & LYD_NODE_TERM));
@@ -1606,9 +1606,10 @@
         /* values differ, switch them */
         type->plugin->free(LYD_CTX(term), &t->value);
         t->value = val;
-        memset(&val, 0, sizeof val);
         val_change = 1;
     } else {
+        /* same values, free the new stored one */
+        type->plugin->free(LYD_CTX(term), &val);
         val_change = 0;
     }
 
@@ -1654,9 +1655,6 @@
     } /* else value changed, LY_SUCCESS */
 
 cleanup:
-    if (val.realtype) {
-        type->plugin->free(LYD_CTX(term), &val);
-    }
     return ret;
 }