From 1b9c085c208d92254f146741f8b8c012a600f73d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C5=ABnas=20Ma=C5=BEeikis?= Date: Wed, 29 May 2019 13:50:07 +0300 Subject: Protocol: new and improved tlv_destroy. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ramūnas Mažeikis --- src/common/protocol.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/common/protocol.c b/src/common/protocol.c index 90dfc92..0002a96 100644 --- a/src/common/protocol.c +++ b/src/common/protocol.c @@ -68,8 +68,24 @@ size_t tlv_data_size(struct tlv_parser *parser) void tlv_destroy(struct tlv *t) { - free(t->data); - t->length = 0; + size_t i = 0; + size_t tlv_count; + struct tlv *arr; + switch (t->type) + { + case REGURAL: + case HEARTBEAT: + case DISCOVERY: + tlv_count = t->length / sizeof(struct tlv); + arr = t->data; + for (i = 0; i < tlv_count; i++) { + tlv_destroy(&arr[i]); + } + default: + free(t->data); + t->length = 0; + break; + } } size_t tlv_raw_size(const struct tlv *t) -- cgit v1.2.3