diff options
author | 2019-05-29 13:50:07 +0300 | |
---|---|---|
committer | 2019-05-29 13:50:07 +0300 | |
commit | 1b9c085c208d92254f146741f8b8c012a600f73d (patch) | |
tree | 59d1cd5df5162a6c060fd8c18c38a0d90adbdc70 /src/common/protocol.c | |
parent | b8d55024bee48c614003a62a716ff8af92861d05 (diff) | |
download | usurpation-1b9c085c208d92254f146741f8b8c012a600f73d.tar.gz usurpation-1b9c085c208d92254f146741f8b8c012a600f73d.tar.bz2 usurpation-1b9c085c208d92254f146741f8b8c012a600f73d.zip |
Protocol: new and improved tlv_destroy.
Signed-off-by: Ramūnas Mažeikis <ramunasnezinomas@gmail.com>
Diffstat (limited to 'src/common/protocol.c')
-rw-r--r-- | src/common/protocol.c | 20 |
1 files 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) |