Hi,

When cleaning the range_info struct, simple free of the struct
is not enough, we have to free contents of char pointers in the
struct as well.

https://fedorahosted.org/freeipa/ticket/4276

-- 
Tomas Babej
Associate Software Engineer | Red Hat | Identity Management
RHCE | Brno Site | IRC: tbabej | freeipa.org 


>From 4752dd7cf5470e4da709ce0f31b9f8d408b79737 Mon Sep 17 00:00:00 2001
From: Tomas Babej <tba...@redhat.com>
Date: Thu, 27 Mar 2014 13:03:33 +0100
Subject: [PATCH] ipa-range-check: Fix memory leaks when freeing range object

When cleaning the range_info struct, simple free of the struct
is not enough, we have to free contents of char pointers in the
struct as well.

https://fedorahosted.org/freeipa/ticket/4276
---
 .../ipa-slapi-plugins/ipa-range-check/ipa_range_check.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/daemons/ipa-slapi-plugins/ipa-range-check/ipa_range_check.c b/daemons/ipa-slapi-plugins/ipa-range-check/ipa_range_check.c
index 0ef33e5869bbcb4f721394ce35e2338095bf5d36..c877a7dc445b31b3de085aa66028d7652df6b9cc 100644
--- a/daemons/ipa-slapi-plugins/ipa-range-check/ipa_range_check.c
+++ b/daemons/ipa-slapi-plugins/ipa-range-check/ipa_range_check.c
@@ -96,6 +96,15 @@ struct domain_info {
     struct domain_info *next;
 };
 
+static void free_range_info(struct range_info *range) {
+    if (range != NULL) {
+        slapi_ch_free_string(&(range->name));
+        slapi_ch_free_string(&(range->domain_id));
+        slapi_ch_free_string(&(range->forest_root_id));
+        slapi_ch_free_string(&(range->id_range_type));
+        free(range);
+    }
+}
 
 static void free_domain_info(struct domain_info *info) {
     if (info != NULL) {
@@ -323,7 +332,7 @@ static int slapi_entry_to_range_info(struct domain_info *domain_info_head,
 
 done:
     if (ret != 0) {
-        free(range);
+        free_range_info(range);
     }
 
     return ret;
@@ -598,7 +607,7 @@ static int ipa_range_check_pre_op(Slapi_PBlock *pb, int modtype)
         }
 
         ranges_valid = check_ranges(new_range, old_range);
-        free(old_range);
+        free_range_info(old_range);
         old_range = NULL;
         if (ranges_valid != 0) {
             ret = LDAP_CONSTRAINT_VIOLATION;
@@ -638,8 +647,8 @@ done:
     slapi_free_search_results_internal(search_pb);
     slapi_pblock_destroy(search_pb);
     slapi_sdn_free(&dn);
-    free(old_range);
-    free(new_range);
+    free_range_info(old_range);
+    free_range_info(new_range);
     if (free_entry) {
         slapi_entry_free(entry);
     }
-- 
1.8.5.3

_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to