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

Memory leak when connect fails? (ITS#864)

Full_Name: Sam Varshavchik
Version: 1.2.11
OS: Linux.
Submission from: (NULL) (

I'm seeing a memory leak in a failed connection attempt.
Here's an example.

#include <lber.h>
#include <ldap.h>

int main()
	LDAP *p;

	for (;;)
		p=ldap_init("", 389);

		if (!p) break;

		       ldap_simple_bind_s(p, "dc=example.com",
	return (0);

If my server is completely down, I end up losing memory here quickly.  If the
server is up, but the password is wrong, I'm not leaking any memory.  If the
password is good, and bind succeeds, I'm not leaking memory either.  Only when
the server is down, and the connect fails, do I have a large leak here.

When the server is down, ldap_simple_bind_s comes back with LDAP_SERVER_DOWN,
and ldap_unbind_s returns with LDAP_SUCCESS, but something gets leaked.

This will mess up a long-running LDAP client that's designed to be fault
that automatically reconnects to the server when it goes back up.