From 456593766c073ab9ea43052d7bb0fceffbff2221 Mon Sep 17 00:00:00 2001 From: Jan Cholasta Date: Mon, 24 Nov 2014 13:57:10 +0000 Subject: [PATCH] Fix memory leak in GetKeytabControl asn1 code https://fedorahosted.org/freeipa/ticket/4713 Reviewed-By: Alexander Bokovoy --- asn1/ipa_asn1.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/asn1/ipa_asn1.c b/asn1/ipa_asn1.c index 50851a804f59bdb3fcb9ba832b093860d914452d..9efca964ac340208f478483ecfbb70b32d72181c 100644 --- a/asn1/ipa_asn1.c +++ b/asn1/ipa_asn1.c @@ -77,12 +77,12 @@ bool ipaasn1_enc_getktreply(int kvno, struct keys_container *keys, { GetKeytabControl_t gkctrl = { 0 }; bool ret = false; + KrbKey_t *KK; gkctrl.present = GetKeytabControl_PR_reply; gkctrl.choice.reply.newkvno = kvno; for (int i = 0; i < keys->nkeys; i++) { - KrbKey_t *KK; KK = calloc(1, sizeof(KrbKey_t)); if (!KK) goto done; KK->key.type = keys->ksdata[i].key.enctype; @@ -109,9 +109,18 @@ bool ipaasn1_enc_getktreply(int kvno, struct keys_container *keys, } ret = encode_GetKeytabControl(&gkctrl, buf, len); + KK = NULL; done: ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_GetKeytabControl, &gkctrl); + if (KK) { + free(KK->key.value.buf); + if (KK->salt) { + free(KK->salt->value.buf); + free(KK->salt); + } + free(KK); + } return ret; } -- 2.1.0