Make asn1buf_destroy return void, since it's a free function. In
authorGreg Hudson <ghudson@mit.edu>
Mon, 9 Feb 2009 21:25:53 +0000 (21:25 +0000)
committerGreg Hudson <ghudson@mit.edu>
Mon, 9 Feb 2009 21:25:53 +0000 (21:25 +0000)
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

src/lib/krb5/asn.1/asn1buf.c
src/lib/krb5/asn.1/asn1buf.h
src/lib/krb5/asn.1/krb5_encode.c

index 71ad03b2460d829ca98363eacd1dbb3e9c4b2938..c6c80a47471b626bf67d053ef75ce3f701971816 100644 (file)
@@ -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
index 874d6db5cc131d17b7c6d76501c01b8d43a440de..33affbb07f67ce4d97a6e545c33c0c37c706ed1a 100644 (file)
@@ -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. */
 
index a6fa305e6236b9d847b4ccef15e683f87c4c9fec..a8ac06a54b680945d7b2790597d332343c09d4d3 100644 (file)
@@ -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;\
 \
 
 /* 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();
 }