diff options
author | Rich Salz <rsalz@openssl.org> | 2015-03-24 07:52:24 -0400 |
---|---|---|
committer | Rich Salz <rsalz@openssl.org> | 2015-03-24 07:52:24 -0400 |
commit | 0dfb9398bb6493d5a56216e0c7039cb3f9fc88c6 (patch) | |
tree | 9ffaa0bec3d0f14092948174eeea90dc8e2ee7c4 /crypto/asn1/tasn_fre.c | |
parent | 7c82e339a677f8546e1456c7a8f6788598a9de43 (diff) |
free NULL cleanup
Start ensuring all OpenSSL "free" routines allow NULL, and remove
any if check before calling them.
This gets ASN1_OBJECT_free and ASN1_STRING_free.
Reviewed-by: Matt Caswell <matt@openssl.org>
Diffstat (limited to 'crypto/asn1/tasn_fre.c')
-rw-r--r-- | crypto/asn1/tasn_fre.c | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/crypto/asn1/tasn_fre.c b/crypto/asn1/tasn_fre.c index 49c5793a49..bdc26f9bb4 100644 --- a/crypto/asn1/tasn_fre.c +++ b/crypto/asn1/tasn_fre.c @@ -85,6 +85,7 @@ static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, const ASN1_AUX *aux = it->funcs; ASN1_aux_cb *asn1_cb; int i; + if (!pval) return; if ((it->itype != ASN1_ITYPE_PRIMITIVE) && !*pval) @@ -116,6 +117,7 @@ static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, i = asn1_get_choice_selector(pval, it); if ((i >= 0) && (i < it->tcount)) { ASN1_VALUE **pchval; + tt = it->templates + i; pchval = asn1_get_field_ptr(pval, tt); ASN1_template_free(pchval, tt); @@ -170,35 +172,41 @@ static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, void ASN1_template_free(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) { - int i; if (tt->flags & ASN1_TFLG_SK_MASK) { STACK_OF(ASN1_VALUE) *sk = (STACK_OF(ASN1_VALUE) *)*pval; + int i; + for (i = 0; i < sk_ASN1_VALUE_num(sk); i++) { - ASN1_VALUE *vtmp; - vtmp = sk_ASN1_VALUE_value(sk, i); + ASN1_VALUE *vtmp = sk_ASN1_VALUE_value(sk, i); + asn1_item_combine_free(&vtmp, ASN1_ITEM_ptr(tt->item), 0); } sk_ASN1_VALUE_free(sk); *pval = NULL; - } else + } else { asn1_item_combine_free(pval, ASN1_ITEM_ptr(tt->item), tt->flags & ASN1_TFLG_COMBINE); + } } void ASN1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it) { int utype; + + /* Special case: if 'it' is a primitive with a free_func, use that. */ if (it) { - const ASN1_PRIMITIVE_FUNCS *pf; - pf = it->funcs; + const ASN1_PRIMITIVE_FUNCS *pf = it->funcs; + if (pf && pf->prim_free) { pf->prim_free(pval, it); return; } } - /* Special case: if 'it' is NULL free contents of ASN1_TYPE */ + + /* Special case: if 'it' is NULL, free contents of ASN1_TYPE */ if (!it) { ASN1_TYPE *typ = (ASN1_TYPE *)*pval; + utype = typ->type; pval = &typ->value.asn1_value; if (!*pval) @@ -235,8 +243,8 @@ void ASN1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it) default: ASN1_STRING_free((ASN1_STRING *)*pval); - *pval = NULL; break; } - *pval = NULL; + if (*pval) + *pval = NULL; } |