From: Theodore Tso Date: Fri, 23 Sep 1994 02:55:29 +0000 (+0000) Subject: Change the interface of krb5_ktfile_read_entry and X-Git-Tag: krb5-1.0-beta4.3~89 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=c5277cb51269b1d5b56bb93764437f8a4d8f265e;p=krb5.git 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. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@4342 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/lib/krb5/keytab/file/ChangeLog b/src/lib/krb5/keytab/file/ChangeLog index 10aeb56fa..d4e6a7b2a 100644 --- a/src/lib/krb5/keytab/file/ChangeLog +++ b/src/lib/krb5/keytab/file/ChangeLog @@ -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. diff --git a/src/lib/krb5/keytab/file/ktf_get_en.c b/src/lib/krb5/keytab/file/ktf_get_en.c index 903cf56a9..59e20aed0 100644 --- a/src/lib/krb5/keytab/file/ktf_get_en.c +++ b/src/lib/krb5/keytab/file/ktf_get_en.c @@ -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; } diff --git a/src/lib/krb5/keytab/file/ktf_next.c b/src/lib/krb5/keytab/file/ktf_next.c index 25810b888..3c2bdc4aa 100644 --- a/src/lib/krb5/keytab/file/ktf_next.c +++ b/src/lib/krb5/keytab/file/ktf_next.c @@ -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; } diff --git a/src/lib/krb5/keytab/file/ktf_remove.c b/src/lib/krb5/keytab/file/ktf_remove.c index 6c500a0db..60cd99fd4 100644 --- a/src/lib/krb5/keytab/file/ktf_remove.c +++ b/src/lib/krb5/keytab/file/ktf_remove.c @@ -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); diff --git a/src/lib/krb5/keytab/file/ktf_util.c b/src/lib/krb5/keytab/file/ktf_util.c index 94d0daaad..a3803eaa8 100644 --- a/src/lib/krb5/keytab/file/ktf_util.c +++ b/src/lib/krb5/keytab/file/ktf_util.c @@ -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 diff --git a/src/lib/krb5/keytab/file/ktfile.h b/src/lib/krb5/keytab/file/ktfile.h index adf4b0504..2536904ba 100644 --- a/src/lib/krb5/keytab/file/ktfile.h +++ b/src/lib/krb5/keytab/file/ktfile.h @@ -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 *));