Change the interface of krb5_ktfile_read_entry and
authorTheodore Tso <tytso@mit.edu>
Fri, 23 Sep 1994 02:55:29 +0000 (02:55 +0000)
committerTheodore Tso <tytso@mit.edu>
Fri, 23 Sep 1994 02:55:29 +0000 (02:55 +0000)
krb5_ktfile_internal_read_entry so that they don't allocate memory for
the top-level structure.  All of their callers didn't need it and were
freeing it anyway.

git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@4342 dc483132-0cff-0310-8789-dd5450dbe970

src/lib/krb5/keytab/file/ChangeLog
src/lib/krb5/keytab/file/ktf_get_en.c
src/lib/krb5/keytab/file/ktf_next.c
src/lib/krb5/keytab/file/ktf_remove.c
src/lib/krb5/keytab/file/ktf_util.c
src/lib/krb5/keytab/file/ktfile.h

index 10aeb56fa365625837d06b9a5de540b739dd460c..d4e6a7b2aab3cf45c4ce6e1f33bad86291f7ada4 100644 (file)
@@ -1,4 +1,15 @@
 Thu Sep 22 21:51:53 1994  Theodore Y. Ts'o  (tytso@dcl)
+    
+       * ktf_get_en.c (krb5_ktfile_get_entry):
+       * ktf_next.c (krb5_ktfile_get_next):
+       * ktf_remove.c (krb5_ktfile_remove):
+       * ktf_util.c (krb5_ktfileint_read_entry,
+               krb5_ktfileint_internal_read_entry):
+       * ktfile.h: Change the interface of krb5_ktfile_read_entry and
+               krb5_ktfile_internal_read_entry so that they don't
+               allocate memory for the top-level structure.  All of their
+               callers didn't need it and were freeing it anyway.
+               
 
        * ktf_remove.c (krb5_ktfile_remove): Fix memory leak caused by not
                freeing the top-level structure.
index 903cf56a982ec8326562c83d58b5139217df9a2c..59e20aed0cafc52ecf52cbd414f238896c3f22e5 100644 (file)
@@ -42,7 +42,7 @@ OLDDECLARG(krb5_principal, principal)
 OLDDECLARG(krb5_kvno, kvno)
 OLDDECLARG(krb5_keytab_entry *, entry)
 {
-    krb5_keytab_entry *cur_entry;
+    krb5_keytab_entry cur_entry;
     krb5_error_code kerror = 0;
 
     /* Open the keyfile for reading */
@@ -54,30 +54,26 @@ OLDDECLARG(krb5_keytab_entry *, entry)
      * is exited with a break statement.
      */
     while (TRUE) {
-       cur_entry = 0;
        if (kerror = krb5_ktfileint_read_entry(id, &cur_entry))
            break;
 
-       if (((kvno == IGNORE_VNO) || (kvno == cur_entry->vno)) &&
-           krb5_principal_compare(principal, cur_entry->principal)) {
+       if (((kvno == IGNORE_VNO) || (kvno == cur_entry.vno)) &&
+           krb5_principal_compare(principal, cur_entry.principal)) {
            /* found a match */
            break;
        }
-       krb5_kt_free_entry(cur_entry);
-       krb5_xfree(cur_entry);
+       krb5_kt_free_entry(&cur_entry);
     }
-    if (kerror && kerror != KRB5_KT_END) {
+    if (kerror) {
+       if (kerror == KRB5_KT_END)
+           kerror = KRB5_KT_NOTFOUND;
        (void) krb5_ktfileint_close(id);
        return kerror;
     }
     if ((kerror = krb5_ktfileint_close(id)) != 0) {
-       krb5_kt_free_entry(cur_entry);
-       krb5_xfree(cur_entry);
+       krb5_kt_free_entry(&cur_entry);
        return kerror;
     }
-    if (!cur_entry)
-       return KRB5_KT_NOTFOUND;
-    *entry = *cur_entry;
-    krb5_xfree(cur_entry);
+    *entry = cur_entry;
     return 0;
 }
index 25810b888c7596ce4564f8d9f41f27aaa3920128..3c2bdc4aabcadc0ba40be0254eafa1ce4f10ef11 100644 (file)
@@ -37,7 +37,7 @@ krb5_keytab_entry *entry;
 krb5_kt_cursor *cursor;
 {
     long *fileoff = (long *)*cursor;
-    krb5_keytab_entry *cur_entry;
+    krb5_keytab_entry cur_entry;
     krb5_error_code kerror;
 
     if (fseek(KTFILEP(id), *fileoff, 0) == -1)
@@ -45,7 +45,6 @@ krb5_kt_cursor *cursor;
     if (kerror = krb5_ktfileint_read_entry(id, &cur_entry))
        return kerror;
     *fileoff = ftell(KTFILEP(id));
-    *entry = *cur_entry;
-    krb5_xfree(cur_entry);
+    *entry = cur_entry;
     return 0;
 }
index 6c500a0db3dfb6c7c3c9d3521570b2a580c513f2..60cd99fd4b8db3d08adc2d224b320b7020794311 100644 (file)
@@ -35,10 +35,9 @@ krb5_ktfile_remove(id, entry)
 krb5_keytab id;
 krb5_keytab_entry *entry;
 {
-    krb5_keytab_entry   *cur_entry;
+    krb5_keytab_entry   cur_entry;
     krb5_error_code     kerror;
     krb5_int32          delete_point;
-    krb5_boolean        found = FALSE;
 
     if (kerror = krb5_ktfileint_openw(id)) {
        return kerror;
@@ -49,34 +48,29 @@ krb5_keytab_entry *entry;
      * is exited with a break statement.
      */
     while (TRUE) {
-       cur_entry = 0;
        if (kerror = krb5_ktfileint_internal_read_entry(id, &cur_entry,
                                                             &delete_point))
            break;
 
-       if ((entry->vno == cur_entry->vno) &&
-            (entry->key.keytype == cur_entry->key.keytype) &&
-           krb5_principal_compare(entry->principal, cur_entry->principal)) {
+       if ((entry->vno == cur_entry.vno) &&
+            (entry->key.keytype == cur_entry.key.keytype) &&
+           krb5_principal_compare(entry->principal, cur_entry.principal)) {
            /* found a match */
-            found = TRUE;
-            krb5_kt_free_entry(cur_entry);
-           krb5_xfree(cur_entry);
+            krb5_kt_free_entry(&cur_entry);
            break;
        }
-       krb5_kt_free_entry(cur_entry);
-       krb5_xfree(cur_entry);
+       krb5_kt_free_entry(&cur_entry);
     }
 
-    if (kerror && kerror != KRB5_KT_END) {
+    if (kerror == KRB5_KT_END)
+       kerror = KRB5_KT_NOTFOUND;
+
+    if (kerror) {
        (void) krb5_ktfileint_close(id);
        return kerror;
     }
 
-    if (found) {
-        kerror = krb5_ktfileint_delete_entry(id, delete_point);
-    } else {
-        kerror = KRB5_KT_NOTFOUND;
-    }
+    kerror = krb5_ktfileint_delete_entry(id, delete_point);
 
     if (kerror) {
        (void) krb5_ktfileint_close(id);
index 94d0daaadcccbdbd61823375c7cd81c3463f6902..a3803eaa82fcedaebdc671e34f5b794e4fdb3eb4 100644 (file)
@@ -243,12 +243,11 @@ krb5_int32 delete_point;
 }
 
 krb5_error_code
-krb5_ktfileint_internal_read_entry(id, entrypp, delete_point)
+krb5_ktfileint_internal_read_entry(id, ret_entry, delete_point)
 krb5_keytab id;
-krb5_keytab_entry **entrypp;
+krb5_keytab_entry *ret_entry;
 krb5_int32 *delete_point;
 {
-    register krb5_keytab_entry *ret_entry;
     krb5_int16 count;
     krb5_int16 princ_size;
     register int i;
@@ -258,8 +257,7 @@ krb5_int32 *delete_point;
     char       *tmpdata;
     krb5_data  *princ;
 
-    if (!(ret_entry = (krb5_keytab_entry *)calloc(1, sizeof(*ret_entry))))
-       return ENOMEM;
+    memset(ret_entry, 0, sizeof(krb5_keytab_entry));
 
     /* fseek to synchronise buffered I/O on the key table. */
 
@@ -308,7 +306,8 @@ krb5_int32 *delete_point;
     ret_entry->principal->length = count;
     ret_entry->principal->data = (krb5_data *)calloc(count, sizeof(krb5_data));
     if (!ret_entry->principal->data) {
-       free(ret_entry->principal);    
+       free(ret_entry->principal);
+       ret_entry->principal = 0;
        return ENOMEM;
     }
 
@@ -422,8 +421,6 @@ krb5_int32 *delete_point;
        goto fail;
     }
 
-    *entrypp = ret_entry;
-
     /*
      * Reposition file pointer to the next inter-record length field.
      */
@@ -437,18 +434,20 @@ fail:
                    free(princ->data);
     }
     free(ret_entry->principal->data);
+    ret_entry->principal->data = 0;
     free(ret_entry->principal);
+    ret_entry->principal = 0;
     return error;
 }
 
 krb5_error_code
-krb5_ktfileint_read_entry(id, entrypp)
+krb5_ktfileint_read_entry(id, entryp)
 krb5_keytab id;
-krb5_keytab_entry **entrypp;
+krb5_keytab_entry *entryp;
 {
     krb5_int32 delete_point;
 
-    return krb5_ktfileint_internal_read_entry(id, entrypp, &delete_point);
+    return krb5_ktfileint_internal_read_entry(id, entryp, &delete_point);
 }
 
 krb5_error_code
index adf4b050421b1dccbb3011c804a2baf3d68c90b7..2536904ba60cdebfa9eb16bf17e26bf0a65a085f 100644 (file)
@@ -93,13 +93,13 @@ krb5_error_code krb5_ktfileint_openr PROTOTYPE((krb5_keytab));
 krb5_error_code krb5_ktfileint_openw PROTOTYPE((krb5_keytab));
 krb5_error_code krb5_ktfileint_close PROTOTYPE((krb5_keytab));
 krb5_error_code krb5_ktfileint_read_entry PROTOTYPE((krb5_keytab,
-                                                    krb5_keytab_entry **));
+                                                    krb5_keytab_entry *));
 krb5_error_code krb5_ktfileint_write_entry PROTOTYPE((krb5_keytab,
                                                      krb5_keytab_entry *));
 krb5_error_code krb5_ktfileint_delete_entry PROTOTYPE((krb5_keytab,
                                                       krb5_int32));
 krb5_error_code krb5_ktfileint_internal_read_entry PROTOTYPE((krb5_keytab,
-                                                    krb5_keytab_entry **,
+                                                    krb5_keytab_entry *,
                                                      krb5_int32 *));
 krb5_error_code krb5_ktfileint_size_entry PROTOTYPE((krb5_keytab_entry *,
                                                       krb5_int32 *));