Debian Codegraph @

src/ltc/pk/asn1/der/sequence/der_sequence_free.c

raw
1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis */
2 /* SPDX-License-Identifier: Unlicense */
3 #include "tomcrypt_private.h"
4
5 /**
6 @file der_sequence_free.c
7 ASN.1 DER, free's a structure allocated by der_decode_sequence_flexi(), Tom St Denis
8 */
9
10 #ifdef LTC_DER
11
12 /**
13 Free memory allocated by der_decode_sequence_flexi()
14 @param in The list to free
15 */
16 void der_sequence_free(ltc_asn1_list *in)
17 {
18 ltc_asn1_list *l;
19
20 if (!in) return;
21
22 /* walk to the start of the chain */
23 while (in->prev != NULL || in->parent != NULL) {
24 if (in->parent != NULL) {
25 in = in->parent;
26 } else {
27 in = in->prev;
28 }
29 }
30
31 /* now walk the list and free stuff */
32 while (in != NULL) {
33 /* is there a child? */
34 if (in->child) {
35 /* disconnect */
36 in->child->parent = NULL;
37 der_sequence_free(in->child);
38 }
39
40 switch (in->type) {
41 case LTC_ASN1_SETOF: break;
42 case LTC_ASN1_INTEGER : if (in->data != NULL) { ltc_mp_clear(in->data); } break;
43 default : if (in->data != NULL) { XFREE(in->data); }
44 }
45
46 /* move to next and free current */
47 l = in->next;
48 XFREE(in);
49 in = l;
50 }
51 }
52
53 #endif