[Date Prev][Date Next]
[Chronological]
[Thread]
[Top]
Re: when to use ldap_msgfree?
> Hi,
>
>
> I need some help with the libldap, guess someone can help me.
> * When I issue two ldap_search_s calls in sequence, consume all their
> results between the two calls and use the same result pointer, is it
> necessary to call ldap_msgfree on this pointer before the second
> ldap_search_s?
Yes. Better said, you should free the result by calling ldap_msgfree
after you are through with it. If you don't, you'll have a memory leak.
> * When I issue an ldap_search_s, go with the result pointer to
> ldap_first_entry collecting the return value in a pointer named entry and
> then, after comsuming the result, call ldap_msgfree on entry, has this any
> effect on the result pointer?
It is incorrect to call ldap_msgfree on an individual entry returned
by ldap_first_entry() or ldap_next_entry(). Ldap_msgfree() frees the
entire chain of results, following the same linked lists that
ldap_next_entry() follows. By doing what you suggest, you will free
the results before you use them, which is unsafe, though you might
get away with it sometimes.
Randy