Blame SOURCES/0001-ensure_keytab_principals-do-not-leak-memory-when-cal.patch

ee8dc1
From 3a84c2469c31967bc22c0490456f07723ef5fc86 Mon Sep 17 00:00:00 2001
ee8dc1
From: Sumit Bose <sbose@redhat.com>
ee8dc1
Date: Wed, 20 Mar 2019 11:01:50 +0100
ee8dc1
Subject: [PATCH 1/4] ensure_keytab_principals: do not leak memory when called
ee8dc1
 twice
ee8dc1
ee8dc1
Related to https://bugzilla.redhat.com/show_bug.cgi?id=1630187
ee8dc1
---
ee8dc1
 library/adenroll.c | 32 +++++++++++++++++++++-----------
ee8dc1
 1 file changed, 21 insertions(+), 11 deletions(-)
ee8dc1
ee8dc1
diff --git a/library/adenroll.c b/library/adenroll.c
ee8dc1
index d1f746c..48cb4cf 100644
ee8dc1
--- a/library/adenroll.c
ee8dc1
+++ b/library/adenroll.c
ee8dc1
@@ -413,6 +413,25 @@ ensure_service_principals (adcli_result res,
ee8dc1
 	return res;
ee8dc1
 }
ee8dc1
 
ee8dc1
+static void enroll_clear_keytab_principals (adcli_enroll *enroll)
ee8dc1
+{
ee8dc1
+	krb5_context k5;
ee8dc1
+	size_t c;
ee8dc1
+
ee8dc1
+	if (enroll->keytab_principals) {
ee8dc1
+		k5 = adcli_conn_get_krb5_context (enroll->conn);
ee8dc1
+		return_if_fail (k5 != NULL);
ee8dc1
+
ee8dc1
+		for (c = 0; enroll->keytab_principals[c] != NULL; c++)
ee8dc1
+			krb5_free_principal (k5, enroll->keytab_principals[c]);
ee8dc1
+
ee8dc1
+		free (enroll->keytab_principals);
ee8dc1
+		enroll->keytab_principals = NULL;
ee8dc1
+	}
ee8dc1
+
ee8dc1
+	return;
ee8dc1
+}
ee8dc1
+
ee8dc1
 static adcli_result
ee8dc1
 ensure_keytab_principals (adcli_result res,
ee8dc1
                           adcli_enroll *enroll)
ee8dc1
@@ -430,6 +449,7 @@ ensure_keytab_principals (adcli_result res,
ee8dc1
 	k5 = adcli_conn_get_krb5_context (enroll->conn);
ee8dc1
 	return_unexpected_if_fail (k5 != NULL);
ee8dc1
 
ee8dc1
+	enroll_clear_keytab_principals (enroll);
ee8dc1
 	enroll->keytab_principals = calloc (count + 3, sizeof (krb5_principal));
ee8dc1
 	return_unexpected_if_fail (enroll->keytab_principals != NULL);
ee8dc1
 	at = 0;
ee8dc1
@@ -1860,18 +1880,8 @@ static void
ee8dc1
 enroll_clear_state (adcli_enroll *enroll)
ee8dc1
 {
ee8dc1
 	krb5_context k5;
ee8dc1
-	int i;
ee8dc1
-
ee8dc1
-	if (enroll->keytab_principals) {
ee8dc1
-		k5 = adcli_conn_get_krb5_context (enroll->conn);
ee8dc1
-		return_if_fail (k5 != NULL);
ee8dc1
-
ee8dc1
-		for (i = 0; enroll->keytab_principals[i] != NULL; i++)
ee8dc1
-			krb5_free_principal (k5, enroll->keytab_principals[i]);
ee8dc1
 
ee8dc1
-		free (enroll->keytab_principals);
ee8dc1
-		enroll->keytab_principals = NULL;
ee8dc1
-	}
ee8dc1
+	enroll_clear_keytab_principals (enroll);
ee8dc1
 
ee8dc1
 	if (enroll->keytab) {
ee8dc1
 		k5 = adcli_conn_get_krb5_context (enroll->conn);
ee8dc1
-- 
ee8dc1
2.20.1
ee8dc1