From c547cc992eec438bd3c877bba5d2cba50228d0e8 Mon Sep 17 00:00:00 2001
From: Paul Bakker
Date: Mon, 9 Sep 2013 12:01:23 +0200
Subject: [PATCH] Added generic asn1_free_named_data_list()
---
include/polarssl/asn1.h | 8 ++++++++
library/asn1parse.c | 12 ++++++++++++
2 files changed, 20 insertions(+)
diff --git a/include/polarssl/asn1.h b/include/polarssl/asn1.h
index ec8cbfafc..86a1bc8c1 100644
--- a/include/polarssl/asn1.h
+++ b/include/polarssl/asn1.h
@@ -319,6 +319,14 @@ asn1_named_data *asn1_find_named_data( asn1_named_data *list,
*/
void asn1_free_named_data( asn1_named_data *entry );
+/**
+ * Free all entries in a asn1_named_data list
+ * Head will be set to NULL
+ *
+ * \param head Pointer to the head of the list of named data entries to free
+ */
+void asn1_free_named_data_list( asn1_named_data **head );
+
#ifdef __cplusplus
}
#endif
diff --git a/library/asn1parse.c b/library/asn1parse.c
index f6b271ec5..957359917 100644
--- a/library/asn1parse.c
+++ b/library/asn1parse.c
@@ -354,6 +354,18 @@ void asn1_free_named_data( asn1_named_data *cur )
memset( cur, 0, sizeof( asn1_named_data ) );
}
+void asn1_free_named_data_list( asn1_named_data **head )
+{
+ asn1_named_data *cur;
+
+ while( ( cur = *head ) != NULL )
+ {
+ *head = cur->next;
+ asn1_free_named_data( cur );
+ polarssl_free( cur );
+ }
+}
+
asn1_named_data *asn1_find_named_data( asn1_named_data *list,
const char *oid, size_t len )
{