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.
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 */
* 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;
}
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)
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;
}
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;
* 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);
}
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;
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. */
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;
}
goto fail;
}
- *entrypp = ret_entry;
-
/*
* Reposition file pointer to the next inter-record length field.
*/
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
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 *));