From 0e8cb78e21063b66a9621a155207762fdcacecc3 Mon Sep 17 00:00:00 2001 From: Theodore Tso Date: Fri, 24 Dec 1993 22:56:46 +0000 Subject: [PATCH] Make sure memory is freed on errors in krb5_rc_io_fetch git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@3284 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/krb5/rcache/rc_dfl.c | 38 +++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/src/lib/krb5/rcache/rc_dfl.c b/src/lib/krb5/rcache/rc_dfl.c index 7cec3df2d..87c4a1b71 100644 --- a/src/lib/krb5/rcache/rc_dfl.c +++ b/src/lib/krb5/rcache/rc_dfl.c @@ -291,6 +291,8 @@ krb5_error_code krb5_rc_io_fetch(t, rep, maxlen) { int len; krb5_error_code retval; + + rep->client = rep->server = 0; retval = krb5_rc_io_read (&t->d, (krb5_pointer) &len, sizeof(len)); if (retval) @@ -304,29 +306,43 @@ krb5_error_code krb5_rc_io_fetch(t, rep, maxlen) return KRB5_RC_MALLOC; retval = krb5_rc_io_read (&t->d, (krb5_pointer) rep->client, len); - if (retval) - return retval; + if (retval) + goto errout; retval = krb5_rc_io_read (&t->d, (krb5_pointer) &len, sizeof(len)); - if (retval) - return retval; + if (retval) + goto errout; - if ((len <= 0) || (len >= maxlen)) - return KRB5_RC_IO_EOF; + if ((len <= 0) || (len >= maxlen)) { + retval = KRB5_RC_IO_EOF; + goto errout; + } rep->server = malloc (len); - if (!rep->server) - return KRB5_RC_MALLOC; + if (!rep->server) { + retval = KRB5_RC_MALLOC; + goto errout; + } retval = krb5_rc_io_read (&t->d, (krb5_pointer) rep->server, len); - if (retval) - return retval; + if (retval) + goto errout; retval = krb5_rc_io_read (&t->d, (krb5_pointer) &rep->cusec, sizeof(rep->cusec)); if (retval) - return retval; + goto errout; retval = krb5_rc_io_read (&t->d, (krb5_pointer) &rep->ctime, sizeof(rep->ctime)); + if (retval) + goto errout; + + return 0; + +errout: + if (rep->client) + krb5_xfree(rep->client); + if (rep->server) + krb5_xfree(rep->server); return retval; } -- 2.26.2