[samba4] Memory leak in LDAP

Andrew Bartlett abartlet at samba.org
Tue Sep 13 21:12:38 GMT 2005


On Tue, 2005-09-13 at 15:39 -0400, Karl Melcher wrote:
> I have tracked a LDAP related memory leak to the data blob of the request 
> structure. Upon sending a LDAP request via ldap_request_send, the data blob 
> is never freed. When the blob is allocated it is passed a NULL memory 
> context, so it is not tied to any other memory that would be freed. 
> 
> Additionally, the data pointer in the ldap_request.data structure is being 
> incremented in the ldap_send_handler() function in ldap_client.c. Therefore, 
> attempting to free it by a direct call to data_blob_free does not work.
> 
> Am I missing something in how this memory is to be managed, or is this a 
> bug? If it's a bug, then I have identified two possible solutions are:

Sounds like a bug to me :-)

> 1. copy the original data blob pointer before it is altered in the 
> ldap_send_handler. Then use this in a call to data_blob_free()
> 2. Pass a memory context to the data blob allocator so it is tied to the 
> request and freed when the request is freed.

All memory should be on a memory context unless there is a *very* good
reason not to.  Preferably one that will last just as long as the memory
is required.

If there is a memory context associated with the request (and preferably
not even the expected reply), then it should be attached to that, or a
new sub-context created for that purpose.

Andrew Bartlett

-- 
Andrew Bartlett                                http://samba.org/~abartlet/
Samba Developer, SuSE Labs, Novell Inc.        http://suse.de
Authentication Developer, Samba Team           http://samba.org
Student Network Administrator, Hawker College  http://hawkerc.net
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://lists.samba.org/archive/samba-technical/attachments/20050914/5ea54360/attachment.bin


More information about the samba-technical mailing list