LDB hidden memory leaks

simo idra at samba.org
Sun Jul 4 15:57:52 MDT 2010

On Mon, 2010-07-05 at 00:38 +0300, Kamen Mazdrashki wrote:
> Hi guys,
> As I wrote in the below mentioned thread, there are few functions in
> LDB implementation
> that are easy to leak memory with at present.
> http://lists.samba.org/archive/samba-technical/2010-July/071967.html
> While this behavior is not a problem for utilities that uses LDB like
> ldbadd for example,
> it is a problem for Samba itself as it is supposed to be working 24/7.
> In case of Samba, memory allocated in ldb_context context and not
> freed quickly is 
>  leaked memory as it will go away with LDB connection, i.e. presumably
> never :)
> I've pushed two approaches to the problem:
> 1) Introduce new functions and declare old ones as obsolete
> http://gitweb.samba.org/?p=kamenim/samba.git;a=shortlog;h=refs/heads/ldb-mem-fix-1
> 2) Allocate memory in NULL context internally, so we will be able to
> notice, when those 
> functions are used in dangerous manner
> http://gitweb.samba.org/?p=kamenim/samba.git;a=shortlog;h=refs/heads/ldb-mem-fix-2
> Both branches affect only ldb_msg_canonicalize() function. It is
> basically the same
> for ldb_msg_diff() function.
> IMO approach 1) is better one as it leaves no doubt of who the owner
> of the memory is.
> But this approach will change LDB ABI a little, which may be not
> acceptable for everyone.
> (If I recall correctly, Simo is a strong defender of LDB ABI)

Kamen, Approach number 1 is not a problem from an ABI point of view.
Adding *new* symbols is a compatible change, only changing or removing
existing symbols is an issue.

The only advice I'd give is to not use _s as that in the ldap library
world usually demotes synchronous vs asynchronous calls.

Alternatives I can see are:
ldb_msg_canonicalize_p (as in parent)

> Approach 2) tries to solve the problem without ABI change but I think
> it will lead us 
> (or other LDB users) to the same problem soon or later.



Simo Sorce
Samba Team GPL Compliance Officer <simo at samba.org>
Principal Software Engineer at Red Hat, Inc. <simo at redhat.com>

More information about the samba-technical mailing list