[gnutls-devel] [PATCH 3/3] _asn1_ordering_set_of(): Fix memory leak in case of error.
Kurt Roeckx
kurt at roeckx.be
Sat Apr 19 19:46:19 CEST 2014
---
lib/minitasn1/coding.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/lib/minitasn1/coding.c b/lib/minitasn1/coding.c
index ef2f96f..5e9864d 100644
--- a/lib/minitasn1/coding.c
+++ b/lib/minitasn1/coding.c
@@ -842,7 +842,7 @@ _asn1_ordering_set_of (unsigned char *der, int der_len, asn1_node node)
{
p_vet = malloc (sizeof (struct vet));
if (p_vet == NULL)
- return;
+ goto error;
p_vet->next = NULL;
p_vet->prev = last;
@@ -859,12 +859,12 @@ _asn1_ordering_set_of (unsigned char *der, int der_len, asn1_node node)
if (asn1_get_tag_der
(der + counter, der_len - counter, &class, &len,
NULL) != ASN1_SUCCESS)
- return;
+ goto error;
counter += len;
len2 = asn1_get_length_der (der + counter, der_len - counter, &len);
if (len2 < 0)
- return;
+ goto error;
counter += len + len2;
}
@@ -907,7 +907,7 @@ _asn1_ordering_set_of (unsigned char *der, int der_len, asn1_node node)
/* change position */
temp = malloc (p_vet->end - counter);
if (temp == NULL)
- return;
+ goto error;
memcpy (temp, der + counter, (p_vet->end) - counter);
memcpy (der + counter, der + (p_vet->end),
@@ -931,6 +931,15 @@ _asn1_ordering_set_of (unsigned char *der, int der_len, asn1_node node)
free (p_vet);
p_vet = first;
}
+ return;
+
+error:
+ while (first != NULL)
+ {
+ p_vet = first;
+ first = first->next;
+ free(p_vet);
+ }
}
/**
--
1.9.1
More information about the Gnutls-devel
mailing list