comparison libtomcrypt/src/pk/asn1/der/sequence/der_sequence_free.c @ 1511:5916af64acd4 fuzz

merge from main
author Matt Johnston <matt@ucc.asn.au>
date Sat, 17 Feb 2018 19:29:51 +0800
parents 6dba84798cd5
children
comparison
equal deleted inserted replaced
1457:32f990cc96b1 1511:5916af64acd4
3 * LibTomCrypt is a library that provides various cryptographic 3 * LibTomCrypt is a library that provides various cryptographic
4 * algorithms in a highly modular and flexible manner. 4 * algorithms in a highly modular and flexible manner.
5 * 5 *
6 * The library is free for all purposes without any express 6 * The library is free for all purposes without any express
7 * guarantee it works. 7 * guarantee it works.
8 *
9 * Tom St Denis, [email protected], http://libtom.org
10 */ 8 */
11 #include "tomcrypt.h" 9 #include "tomcrypt.h"
12 10
13 /** 11 /**
14 @file der_sequence_free.c 12 @file der_sequence_free.c
18 #ifdef LTC_DER 16 #ifdef LTC_DER
19 17
20 /** 18 /**
21 Free memory allocated by der_decode_sequence_flexi() 19 Free memory allocated by der_decode_sequence_flexi()
22 @param in The list to free 20 @param in The list to free
23 */ 21 */
24 void der_sequence_free(ltc_asn1_list *in) 22 void der_sequence_free(ltc_asn1_list *in)
25 { 23 {
26 ltc_asn1_list *l; 24 ltc_asn1_list *l;
27 25
26 if (!in) return;
27
28 /* walk to the start of the chain */ 28 /* walk to the start of the chain */
29 while (in->prev != NULL || in->parent != NULL) { 29 while (in->prev != NULL || in->parent != NULL) {
30 if (in->parent != NULL) { 30 if (in->parent != NULL) {
31 in = in->parent; 31 in = in->parent;
32 } else { 32 } else {
33 in = in->prev; 33 in = in->prev;
34 } 34 }
35 } 35 }
36 36
37 /* now walk the list and free stuff */ 37 /* now walk the list and free stuff */
38 while (in != NULL) { 38 while (in != NULL) {
39 /* is there a child? */ 39 /* is there a child? */
40 if (in->child) { 40 if (in->child) {
41 /* disconnect */ 41 /* disconnect */
42 in->child->parent = NULL; 42 in->child->parent = NULL;
43 der_sequence_free(in->child); 43 der_sequence_free(in->child);
44 } 44 }
45 45
46 switch (in->type) { 46 switch (in->type) {
47 case LTC_ASN1_SET: 47 case LTC_ASN1_SETOF: break;
48 case LTC_ASN1_SETOF:
49 case LTC_ASN1_SEQUENCE: break;
50 case LTC_ASN1_INTEGER : if (in->data != NULL) { mp_clear(in->data); } break; 48 case LTC_ASN1_INTEGER : if (in->data != NULL) { mp_clear(in->data); } break;
51 default : if (in->data != NULL) { XFREE(in->data); } 49 default : if (in->data != NULL) { XFREE(in->data); }
52 } 50 }
53 51
54 /* move to next and free current */ 52 /* move to next and free current */
55 l = in->next; 53 l = in->next;
56 free(in); 54 XFREE(in);
57 in = l; 55 in = l;
58 } 56 }
59 } 57 }
60 58
61 #endif 59 #endif
62 60
63 /* $Source$ */ 61 /* ref: $Format:%D$ */
64 /* $Revision$ */ 62 /* git commit: $Format:%H$ */
65 /* $Date$ */ 63 /* commit time: $Format:%ai$ */