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

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