On 04/01/2014 09:17 AM, Tomas Babej wrote:
> On 04/01/2014 09:11 AM, Alexander Bokovoy wrote:
>> On Tue, 01 Apr 2014, Jan Pazdziora wrote:
>>> On Thu, Mar 27, 2014 at 01:14:52PM +0100, Tomas Babej wrote:
>>>> 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
>>> [...]
>>>
>>>
>>>>  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);
>>>> +    }
>>>> +}
>>> In master, the range_info is
>>>
>>>     struct range_info {
>>>         char *name;
>>>         char *domain_id;
>>>         uint32_t base_id;
>>>         uint32_t id_range_size;
>>>         uint32_t base_rid;
>>>         uint32_t secondary_base_rid;
>>>     };
>>>
>>> -- no forest_root_id and no id_range_type.
>>>
>>> So NACK for applying to master. Perhaps there is some dependency
>>> patch?
>> I think Tomas took his own range check patch into account.
>>
>> I would also prefer splitting their dependencies. First make this one to
>> work on master, then add forest_root_id and id_range_type freeing as
>> part of the range check patches.
>>
> Yes, that was the intention. Mistake on my part, I'll send updated patches.
>

Updated patch attached.

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

>From d6d0d8a05fe138ec93e6dc0c6015e59c040aca78 Mon Sep 17 00:00:00 2001
From: Tomas Babej <tba...@redhat.com>
Date: Tue, 1 Apr 2014 09:20:09 +0200
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  | 16 ++++++++++++----
 1 file changed, 12 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 391e2259b6eced31fed399c927cfe44c1d3e237e..4f0640eafdaed38cbf72beccc146009a599fa108 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
@@ -78,6 +78,14 @@ struct range_info {
     uint32_t secondary_base_rid;
 };
 
+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));
+        free(range);
+    }
+}
+
 static int slapi_entry_to_range_info(struct slapi_entry *entry,
                                      struct range_info **_range)
 {
@@ -131,7 +139,7 @@ static int slapi_entry_to_range_info(struct slapi_entry *entry,
 
 done:
     if (ret != 0) {
-        free(range);
+        free_range_info(range);
     }
 
     return ret;
@@ -388,7 +396,7 @@ static int ipa_range_check_pre_op(Slapi_PBlock *pb, int modtype)
         }
 
         no_overlap = ranges_overlap(new_range, old_range);
-        free(old_range);
+        free_range_info(old_range);
         old_range = NULL;
         if (no_overlap != 0) {
             ret = LDAP_CONSTRAINT_VIOLATION;
@@ -426,8 +434,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