From 9afdb938cd5e3c86d72d7ef8c5a8fced13291c9c Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sat, 3 Dec 2005 00:47:51 +0000 Subject: r12037: Fix malloc corruption caused by double-free(), where realloc(ptr, 0) is equivilant to free(). This is the issue tridge was seeing in the MEMORY: keytab code. Andrew Bartlett (This used to be commit d5a2de8ef06a08274d25ab005f2a68ec32e226f0) --- source4/heimdal/lib/krb5/keytab_memory.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'source4') diff --git a/source4/heimdal/lib/krb5/keytab_memory.c b/source4/heimdal/lib/krb5/keytab_memory.c index afa8f433ac..1039847de9 100644 --- a/source4/heimdal/lib/krb5/keytab_memory.c +++ b/source4/heimdal/lib/krb5/keytab_memory.c @@ -214,9 +214,15 @@ mkt_remove_entry(krb5_context context, krb5_clear_error_string (context); return KRB5_KT_NOTFOUND; } - e = realloc(d->entries, d->num_entries * sizeof(*d->entries)); - if(e != NULL) - d->entries = e; + if (d->num_entries == 0) { + free(d->entries); + d->entries = NULL; + } else { + e = realloc(d->entries, d->num_entries * sizeof(*d->entries)); + if(e != NULL) + d->entries = e; + } + return 0; } -- cgit