From: Greg Hudson Date: Mon, 9 Feb 2009 21:25:53 +0000 (+0000) Subject: Make asn1buf_destroy return void, since it's a free function. In X-Git-Tag: krb5-1.8-alpha1~676 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=d041ae3172000f4b159b757fb7f8770de79a3f3c;p=krb5.git Make asn1buf_destroy return void, since it's a free function. In krb5_encode.c functions, make *code well-defined in case of error, and clean up some memory leaks. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@21928 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/lib/krb5/asn.1/asn1buf.c b/src/lib/krb5/asn.1/asn1buf.c index 71ad03b24..c6c80a474 100644 --- a/src/lib/krb5/asn.1/asn1buf.c +++ b/src/lib/krb5/asn.1/asn1buf.c @@ -154,14 +154,13 @@ asn1_error_code asn1buf_skiptail(asn1buf *buf, const unsigned int length, const return 0; } -asn1_error_code asn1buf_destroy(asn1buf **buf) +void asn1buf_destroy(asn1buf **buf) { if (*buf != NULL) { free((*buf)->base); free(*buf); *buf = NULL; } - return 0; } #ifdef asn1buf_insert_octet diff --git a/src/lib/krb5/asn.1/asn1buf.h b/src/lib/krb5/asn.1/asn1buf.h index 874d6db5c..33affbb07 100644 --- a/src/lib/krb5/asn.1/asn1buf.h +++ b/src/lib/krb5/asn.1/asn1buf.h @@ -129,7 +129,7 @@ asn1_error_code asn1buf_skiptail constructed indefinite sequence. effects skips trailing fields. */ -asn1_error_code asn1buf_destroy +void asn1buf_destroy (asn1buf **buf); /* effects Deallocates **buf, sets *buf to NULL. */ diff --git a/src/lib/krb5/asn.1/krb5_encode.c b/src/lib/krb5/asn.1/krb5_encode.c index a6fa305e6..a8ac06a54 100644 --- a/src/lib/krb5/asn.1/krb5_encode.c +++ b/src/lib/krb5/asn.1/krb5_encode.c @@ -44,6 +44,9 @@ asn1_error_code retval;\ unsigned int length, sum = 0;\ asn1buf *buf=NULL;\ + krb5_data *tmpcode;\ +\ + *code = NULL;\ \ if (rep == NULL) return ASN1_MISSING_FIELD;\ \ @@ -52,21 +55,19 @@ /* produce the final output and clean up the workspace */ #define krb5_cleanup()\ - retval = asn12krb5_buf(buf,code);\ - if (retval) {\ - asn1buf_destroy(&buf);\ - return retval; }\ - retval = asn1buf_destroy(&buf);\ - if (retval) {\ - return retval; }\ -\ + retval = asn12krb5_buf(buf,&tmpcode);\ +error:\ + asn1buf_destroy(&buf);\ + if (retval)\ + return retval;\ + *code = tmpcode;\ return 0 krb5_error_code encode_krb5_pa_pk_as_req(const krb5_pa_pk_as_req *rep, krb5_data **code) { krb5_setup(); retval = asn1_encode_pa_pk_as_req(buf,rep,&length); - if (retval) return retval; + if (retval) goto error; sum += length; krb5_cleanup(); } @@ -75,7 +76,7 @@ krb5_error_code encode_krb5_pa_pk_as_req_draft9(const krb5_pa_pk_as_req_draft9 * { krb5_setup(); retval = asn1_encode_pa_pk_as_req_draft9(buf,rep,&length); - if (retval) return retval; + if (retval) goto error; sum += length; krb5_cleanup(); } @@ -84,7 +85,7 @@ krb5_error_code encode_krb5_pa_pk_as_rep(const krb5_pa_pk_as_rep *rep, krb5_data { krb5_setup(); retval = asn1_encode_pa_pk_as_rep(buf,rep,&length); - if (retval) return retval; + if (retval) goto error; sum += length; krb5_cleanup(); } @@ -93,7 +94,7 @@ krb5_error_code encode_krb5_pa_pk_as_rep_draft9(const krb5_pa_pk_as_rep_draft9 * { krb5_setup(); retval = asn1_encode_pa_pk_as_rep_draft9(buf,rep,&length); - if (retval) return retval; + if (retval) goto error; sum += length; krb5_cleanup(); } @@ -102,7 +103,7 @@ krb5_error_code encode_krb5_auth_pack(const krb5_auth_pack *rep, krb5_data **cod { krb5_setup(); retval = asn1_encode_auth_pack(buf,rep,&length); - if (retval) return retval; + if (retval) goto error; sum += length; krb5_cleanup(); } @@ -111,7 +112,7 @@ krb5_error_code encode_krb5_auth_pack_draft9(const krb5_auth_pack_draft9 *rep, k { krb5_setup(); retval = asn1_encode_auth_pack_draft9(buf,rep,&length); - if (retval) return retval; + if (retval) goto error; sum += length; krb5_cleanup(); } @@ -120,7 +121,7 @@ krb5_error_code encode_krb5_kdc_dh_key_info(const krb5_kdc_dh_key_info *rep, krb { krb5_setup(); retval = asn1_encode_kdc_dh_key_info(buf,rep,&length); - if (retval) return retval; + if (retval) goto error; sum += length; krb5_cleanup(); } @@ -129,7 +130,7 @@ krb5_error_code encode_krb5_reply_key_pack(const krb5_reply_key_pack *rep, krb5_ { krb5_setup(); retval = asn1_encode_reply_key_pack(buf,rep,&length); - if (retval) return retval; + if (retval) goto error; sum += length; krb5_cleanup(); } @@ -138,7 +139,7 @@ krb5_error_code encode_krb5_reply_key_pack_draft9(const krb5_reply_key_pack_draf { krb5_setup(); retval = asn1_encode_reply_key_pack_draft9(buf,rep,&length); - if (retval) return retval; + if (retval) goto error; sum += length; krb5_cleanup(); } @@ -147,7 +148,7 @@ krb5_error_code encode_krb5_td_trusted_certifiers(const krb5_external_principal_ { krb5_setup(); retval = asn1_encode_td_trusted_certifiers(buf,rep,&length); - if (retval) return retval; + if (retval) goto error; sum += length; krb5_cleanup(); } @@ -156,7 +157,7 @@ krb5_error_code encode_krb5_typed_data(const krb5_typed_data **rep, krb5_data ** { krb5_setup(); retval = asn1_encode_sequence_of_typed_data(buf,rep,&length); - if (retval) return retval; + if (retval) goto error; sum += length; krb5_cleanup(); } @@ -165,7 +166,7 @@ krb5_error_code encode_krb5_td_dh_parameters(const krb5_algorithm_identifier **r { krb5_setup(); retval = asn1_encode_sequence_of_algorithm_identifier(buf,rep,&length); - if (retval) return retval; + if (retval) goto error; sum += length; krb5_cleanup(); }