[Date Prev][Date Next] [Chronological] [Thread] [Top]

[newbie] Problem with memory deallocation in ldap_controls_free



Hello,

I need advice with memory management in ldap_controls_free and maybe
have a small patch proposal.

ldap_controls_free uses LDAP_FREE which uses ber_memfree_x which isn't
exported to applications (the same with it's counterpart
ber_memalloc_x).

When using controls that are returned from the server this is ok
because the controls array is created by the ldap lib.  But when I'm
sending controls I currently can't see a way how I can allocate the
controls array I need using ber_memalloc_x.  Therefore I have to use
CRT's malloc and therefore I can't use ldap_controls_free for these
controls array (segfaults when LDAP_MEMORY_DEBUG is used).

What have I overlooked?  What do other applications do?  All examples
I have seen so far (ldapsearch.c and nss-ldap) use fixed size stack
variables, which are not usable in my use case.

Anyway it would possibly be nice to have something like the following
exported to the user (in controls.c):

int ldap_controls_allocate(unsigned num, LDAPControl ***ctrls) {
    int res = LDAP_SUCCESS;
    int i;
    LDAPControl **c = (LDAPControl**) LDAP_MALLOC((num+1) sizeof(LDAPControl*));
    if (c)
       for (i = 0; i < num+1; i++)
           c[i] = 0;
    else
       res = LDAP__NO_MEMORY;
   *ctrls = c;
   return res;
}

This way a I could use ldap_controls_free for all controls arrays.


TIA,

aa

-- 
Andreas Ames | Programmer | Comergo GmbH | 
Voice:  +49 69 7505 3213 | andreas . ames AT comergo . com