data FEATURE support for validating and parsing bits values
diff --git a/src/tree_data_free.c b/src/tree_data_free.c
index f720857..f594872 100644
--- a/src/tree_data_free.c
+++ b/src/tree_data_free.c
@@ -23,6 +23,7 @@
 #include "tree_data.h"
 #include "tree_schema.h"
 #include "tree_data_internal.h"
+#include "plugins_types.h"
 
 API LY_ERR
 lyd_unlink_tree(struct lyd_node *node)
@@ -78,9 +79,14 @@
  * @param[in] value Data value structure to clean - since it is mostly part of other structure, only content is freed.
  */
 static void
-lyd_free_value(struct ly_ctx *ctx, struct lyd_value *value)
+lyd_free_value(struct ly_ctx *ctx, struct lyd_value *value, struct lysc_type *type)
 {
+    if (type->plugin->free) {
+        type->plugin->free(ctx, type, value);
+    }
+
     FREE_STRING(ctx, value->canonized);
+
 }
 
 API void
@@ -121,7 +127,7 @@
         iter = iter->next;
 
         FREE_STRING(ctx, attr->name);
-        lyd_free_value(ctx, &attr->value);
+        lyd_free_value(ctx, &attr->value, NULL /* TODO */);
         free(attr);
     }
 }
@@ -178,7 +184,7 @@
         }
 #endif
     } else if (node->schema->nodetype & LYD_NODE_TERM) {
-        lyd_free_value(ctx, &((struct lyd_node_term*)node)->value);
+        lyd_free_value(ctx, &((struct lyd_node_term*)node)->value, ((struct lysc_node_leaf*)node->schema)->type);
     }
 
     /* free the node's attributes */