ldb_search interface considered harmful

simo idra at samba.org
Tue Jan 31 14:18:27 GMT 2006


On Tue, 2006-01-31 at 16:02 +1100, Andrew Bartlett wrote:
> I've recently been working on the Samba4 code, and the output of
> --leak-report-full in particular.
> 
> The contents of this (for an inactive connection) should be quite small,
> but I initially found a large number of ldb_message structures being
> kept around.  While some of this was easy to clean up, the problem
> appears to be the interface:
> 
> int ldb_search(struct ldb_context *ldb,
>                const struct ldb_dn *base,
>                enum ldb_scope scope,
>                const char *expression,
>                const char * const *attrs, struct ldb_result **res);
> 
> Because the *res is returned on the ldb as a context, it often stays
> there.  The gendb wrapper 'fixes' this, but we don't always use it.
> Should we modify the interface to have an explicit mem_ctx argument, to
> avoid the caller needing to manually talloc_steal?

I would like to avoid passing down a mem_ctx and just document the fact.
The API is made to be usable in any program and probably avoiding
programs to be forced into using talloc is preferable.
You should always free the result once done with a call, and talloc
should then free everything down that path.

Simo.

-- 
Simo Sorce
Samba Team
email: idra at samba.org
http://samba.org/~idra



More information about the samba-technical mailing list